tableview problem

Post

Posted
Rating:
#1 (In Topic #178)
Regular
bill-lancaster is in the usergroup ‘Regular’
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

' 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

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
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.

Code (gambas)

  1. Public Sub Form_Open()
  2.   tbvInvoices.Columns.Count = 3
  3.   tbvInvoices.Rows.Count = 5
  4.  
  5. Public Sub tbvInvoices_Click()
  6.   tbvInvoices.EditWith(TextBox1)
  7.  
  8. Public Sub tbvInvoices_Save(Row As Integer, Column As Integer, Value As String)
  9.   tbvInvoices[Row, Column].Text = Value
  10.  
  11. Public Sub TextBox1_Change()
  12.   If IsNumber(Right(TextBox1.Text)) Then TextBox1.Text = Left(TextBox1.Text, -1)

I hope that helps.
Online now: Yes Back to the top

Post

Posted
Rating:
#3
Regular
bill-lancaster is in the usergroup ‘Regular’
Thanks, that is a neat work around.
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
bill-lancaster is in the usergroup ‘Regular’
I realised that a more positive indication that the value entered wasn't acceptable so a message was really called for so:-

Code

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!
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
jornmo is in the usergroup ‘Regular’
Perhaps you could utilize an observer on the key release, and call the stop event when not a number.

Online now: No Back to the top
1 guest and 0 members have just viewed this.