ComboBox.RowTagAt(SelectedRowIndex).IsNull

Hello group, I’m trying to handle the various types of errors from the user: I have problems in the row:
if ComboBoxNomiFornitori.RowTagAt(ComboBoxNomiFornitori.SelectedRowIndex).IsNull then

When the value in the combobox is there, I pass the ID to rowtag, when it is not there I have the error.

error: OutOfBoundsException

SelectedRowIndex can be -1 if nothing is selected. Could that be the issue?

1 Like

I select or insert a value in a ComboBoxNomiFornitori.Text , if ComboBoxNomiFornitori.Text exist return
ID in ComboBoxNomiFornitori.RowTagAt(ComboBoxNomiFornitori.SelectedRowIndex).stringvalue
if ComboBoxNomiFornitori.Text NOT exist value, return ID NULL ? in ComboBoxNomiFornitori.RowTagAt(ComboBoxNomiFornitori.SelectedRowIndex).stringvalue ?

This is my problem.

When you post code, it helps the reader if you:

  1. Add the code to your post
  2. select the code with the mouse
  3. Click </>

Thanks.

1 Like

Our problem is reading what you have posted.

1 Like

I have a combobox, where I load names, each name is associated with an ID…on the combox there are names on the RowTag the IDs.

    While Not rows.AfterLastRow
      ComboBoxNomiFornitori.AddRow(rows.Column("NomeDitta").StringValue)
      ComboBoxNomiFornitori.RowTagAt(ComboBoxNomiFornitori.LastAddedRowIndex) = rows.Column("ID").StringValue
      rows.MoveToNextRow
    Wend

But it could happen that the user writes a name for which there is no ID and here comes the problem in the code:

if ComboBoxNomiFornitori.RowTagAt(ComboBoxNomiFornitori.SelectedRowIndex).stringvalue="" then

return error: OutOfBoundsException

I think that the error is because RowTagAT not have any value, is empty !! But how do you manage this?

Where do the IDs come from?

from a databse sqllite table.
but the user can also decide to write a name, of which, then, no ID will be found if there is no match.

i also tried with:

```
if ComboBoxNomiFornitori.RowTagAt(ComboBoxNomiFornitori.SelectedRowIndex).IsNull then
```

but return an error.

Is your idea to generate an ID if none exists because the user is new? If so you should check the name against the ID database first, and if there is no ID, generate one and add it to the table before doing anything else.

Yes indeed now I am writing a code that does this. But my original idea was another. When the program opens I load the data in the combobox (Name in the visible list of the combobox + ID in the Rowtag). When I select an existing name no problem, I retrieve the associated ID … but if I do not use the combo and the user types a name that is not there, I thought that the rowtag would return some value like -1 or NILL, since nothing was selected. I wanted to avoid having to search for the data again, that’s all.

If your table has two columns (NomeDitta and ID), then you know that there is no ID for a name when you load the combobox. So set the rowtag to Nil at that point. What is the schema for that table in your SQLite database? Does the ID column have a default value? I would have expected the ID to be an integer biut you are loading a string into the rowtag.

That’s what I wanted to do, but apparently I can’t, I tried:

if ComboBoxNomiFornitori.RowTagAt(ComboBoxNomiFornitori.SelectedRowIndex).IntegerValue=-1 then     RETURN ERROR

if ComboBoxNomiFornitori.RowTagAt(ComboBoxNomiFornitori.SelectedRowIndex).IsNull then    RETURN ERROR

I can’t figure out how I can tell the program that if I haven’t selected anything from the listbox, it means the ID isn’t there!!

I write this and work fine:

rows = db.SelectSQL("SELECT * FROM NominativiDitte where NomeDitta='"+txtfield1(3).text+"'")
Dim ID_NominativoControllato as string
ID_NominativoControllato=""
While Not Rows.AfterLastRow
  ID_NominativoControllato=rows.Column("ID").StringValue   'Se c'è ID lo prelevo
  rows.MoveToNextRow
Wend

if ID_NominativoControllato="" then
  messagebox " Nome IS NEW, I INSERT THIS"
  RecordTEMPORANEO1.Column("NomeDitta") = txtfield1(3).text
  db.AddRow("NominativiDitte", RecordTEMPORANEO1)
  UltimoIdInserito=db.LastRowID.ToString
  messagebox "LAST ID IS /THE ID OF LAST NAME INSERT:=" + UltimoIdInserito
else
  messagebox " The NAME EXIST , i find ID"
  rows = db.SelectSQL("SELECT * FROM NominativiDitte where NomeDItta='"+txtfield1(3).text+"'")
  UltimoIdInserito=ID_NominativoControllato   'Se c'è ID lo prelevo
  messagebox "ID FROM NAME IS=" + UltimoIdInserito
end if

Presumably because the TextChanged event fires instead of (or as well as) SelectionChanged. You should do some testing to see what event(s) fire and then design your code around that.

My guess is you are seeing the OutOfBound error before you even get the Row tag.

I think your code should be this:

if ComboBoxNomiFornitori.SelectedRowIndex = -1 then RETURN ERROR

Ok that works for me, if I don’t select anything I can manage it. Thanks.

1 Like