Page 1 of 1

tableview problem

Posted: Sunday 1st July 2018 12:25pm
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

Re: tableview problem

Posted: Sunday 1st July 2018 4:02pm
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.

Re: tableview problem

Posted: Monday 2nd July 2018 6:41am
by bill-lancaster
Thanks, that is a neat work around.

Re: tableview problem

Posted: Tuesday 3rd July 2018 9:03am
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!

Re: tableview problem

Posted: Thursday 5th July 2018 8:11am
by jornmo
Perhaps you could utilize an observer on the key release, and call the stop event when not a number.