views:

455

answers:

1

I am using DevExpress.XtraEditors.LookUpEdit to display the information about the classes available. Currently it has 3 columns. The lookupedit is working perfectly except when I set the editValue to the last row. When the editvalue is set to any row other than the last one it shows the selected row when the lookupedit isn't opened yet when the lookupedit is set to the last row nothing is displayed. Currently I am :

lookupedit.Properties.ForceInitialize() ' Force it to initialize
lookupedit.Properties.PopulateColumns() ' Force the lookupedit to populate
   For i As Integer = 0 To tableData.Rows.Count - 1  ' Go through the information in it
      If lblClassVal.Text = tableData.Rows(i).Item(1).ToString() Then ' if the current row is equal to the value I want to select
          lookupedit.EditValue = i + 1 ' then I set the lookupedit value
      End If
   Next i
lookupedit.Properties.Columns("class_id").Visible = False  ' set two columns to invisible
lookupedit.Properties.Columns("active").Visible = False
lookupedit.Properties.Columns("class_name").Caption = "Class Name" ' set the 3rd column to a better title

Right now the lookupedit displays the selected text unless I select the last row, row number tableData.Rows.Count which then displays nothing. Yet when I print the values they are correct and when I remove the +1 when setting the lookupedit it sets it to the previous line I want an the first row can't be displayed.

A: 

Ok I solved this. Just in case someone else if having this problem I will leave the question up.

So the DevExpress LookUpEdit doesn't use the row number, it uses the ID column in your LookUpEdit table. So instead of selecting this by the row number set the EditValue to the ID number of the row you want to select. So instead of:

If lblClassVal.Text = tableData.Rows(i).Item(1).ToString() Then ' if the current row is equal to the value I want to select
   lookupedit.EditValue = i + 1 ' then I set the lookupedit value
End If

Use :

If lblClassVal.Text = tableData.Rows(i).Item(1).ToString() Then ' if the current row is equal to the value I want to select
   lookupedit.EditValue = tableData.Rows(i).Item(0).ToString() ' Where Item(0) is my ID number column
End If
Kyra