tableview problem

Post Reply
bill-lancaster
Posts: 32
Joined: Tuesday 26th September 2017 3:17pm

tableview problem

Post by bill-lancaster » Sunday 01st July 2018 12:25pm

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 408 times

User avatar
cogier
Site Admin
Posts: 193
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: tableview problem

Post by cogier » Sunday 01st July 2018 4:02pm

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: 32
Joined: Tuesday 26th September 2017 3:17pm

Re: tableview problem

Post by bill-lancaster » Monday 02nd July 2018 6:41am

Thanks, that is a neat work around.

bill-lancaster
Posts: 32
Joined: Tuesday 26th September 2017 3:17pm

Re: tableview problem

Post by bill-lancaster » Tuesday 03rd July 2018 9:03am

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: 172
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: tableview problem

Post by jornmo » Thursday 05th July 2018 8:11am

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

Post Reply