tableview problem

Post your Gambas programming questions here.
Post Reply
bill-lancaster
Posts: 190
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

tableview problem

Post by bill-lancaster »

I want to test the value being entered in a cell and if the test fails, then the value isn't entered.
Trouble is that the warning message appears twice

Code: Select all

' Gambas class file


Public Sub Form_Open()
  tbvInvoices.Columns.Count = 3
  tbvInvoices.Rows.Count = 5
End

Public Sub tbvInvoices_Click()
  tbvInvoices.Edit
End

Public Sub tbvInvoices_Save(Row As Integer, Column As Integer, Value As String)
  If IsNumber(Value) Then
    Message.Error("only non-numeric")
    Return
  Endif
  tbvInvoices[Row, Column].Text = Value
End
Any ideas would be appreciated

gambas 3.9.2
Attachments
.icon.png
.icon.png (10.51 KiB) Viewed 6570 times
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: tableview problem

Post by cogier »

I have no idea why the routine is called twice. It may be a bug?

However I have created a possible work around. On your existing Form add a TextBox called TextBox1 and set the Visible property to False. Then run the following code. No error message will be displayed as no numbers will get on the Table.
Public Sub Form_Open()
  tbvInvoices.Columns.Count = 3
  tbvInvoices.Rows.Count = 5
End

Public Sub tbvInvoices_Click()
  tbvInvoices.EditWith(TextBox1)
End

Public Sub tbvInvoices_Save(Row As Integer, Column As Integer, Value As String)
  tbvInvoices[Row, Column].Text = Value
End

Public Sub TextBox1_Change()
  If IsNumber(Right(TextBox1.Text)) Then TextBox1.Text = Left(TextBox1.Text, -1)
End
I hope that helps.
bill-lancaster
Posts: 190
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: tableview problem

Post by bill-lancaster »

Thanks, that is a neat work around.
bill-lancaster
Posts: 190
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: tableview problem

Post by bill-lancaster »

I realised that a more positive indication that the value entered wasn't acceptable so a message was really called for so:-

Code: Select all

Public Sub gdvInvoices_Click()
	bSet = True
	gdvInvoices.Edit
End
Public Sub gdvInvoices_Save(Row As Integer, Column As Integer, Value As String)
If Value = "not acceptable" Then
   If bSet Then Message("not acceptable")
   bSet = False
   Return
Endif
   gdvInvoices[Row, Column].Text = Value
End
This clumsy, but it works!
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: tableview problem

Post by jornmo »

Perhaps you could utilize an observer on the key release, and call the stop event when not a number.
Post Reply