Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Get index of selected item in lookuplist column ?

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Get index of selected item in lookuplist column ?
Link Posted: 25-Jan-2006 04:15
Hi,
I have two lookuplistcolumns with the same number of items. One of the columns is invisible.

What I want to do is that if the user selects an item in the first lookuplistcolumn, the corresponding item (that is the one with the same index) in the other lookuplistcolumn is automatically selected.

How can I do that ? On which event ? What is the property to get the index of the selected item in the list ?

Thanks
Link Posted: 25-Jan-2006 05:47
I've found out  

In NodeSelectedChange event I do :

  If node IsNot Nothing Then
            Dim idx As Integer = m_QueryName.GetValueList(node).IndexOf(m_QueryName.GetValueList(node), m_QueryName.GetValue(node))
            If idx > 0 Then
                m_QueryId.SetValue(node, m_QueryId.GetValueList(node).GetValue(idx))
            End If

        End If


m_QueryName and m_QueryId being my 2 lookuplistcolumns.

It works but is it the best way ? Do you have a better solution ?

Thanks
Link Posted: 25-Jan-2006 10:21
It will be better if you place this code into FlyGrid.NodeCellChange event handler and change cell value of corresponding column after cell contens is changed.
Link Posted: 25-Jan-2006 22:05
OK, here is my code now in NodeCellChange event:


  If index = 0 Then
            Dim idx As Integer = m_QueryName.GetValueList(dgQueries.Selected).IndexOf(m_QueryName.GetValueList(dgQueries.Selected), m_QueryName.GetValue(dgQueries.Selected))
            If idx > 0 Then
                dgQueries.Rows.Items(dgQueries.Selected.Index()).Item(3) = m_QueryId.GetValueList(node).GetValue(idx)
            End If
   End If


I had to use  dgQueries.Rows.Items(dgQueries.Selected.Index()).Item(3) instead of  m_QueryId.SetValue(...) as I was doing before, because otherwise it changes the value of the correct cell but on the row below !!! Why ? Could you check my code please ?
Thanks
Link Posted: 26-Jan-2006 12:24
[Vb.Net]
Private Sub flyGrid_NodeCellChange(ByVal sender As Object, ByVal node As NineRays.Windows.Forms.Data.NodeBase, ByVal index As Integer, ByVal value As Object) Handles flyGrid.NodeCellChange
  If (index = 0) Then    
    Dim idx As Integer = m_QueryName.GetValueList(dgQueries.Selected).IndexOf(m_QueryName.GetValueList(dgQueries.Selected), m_QueryName.GetValue(dgQueries.Selected))
    If (idx > 0) Then
      'node(3) = m_QueryId.GetValueList(node).GetValue(idx)
      ' or
      dgQueries.Rows.Items(node.Index())(3) = m_QueryId.GetValueList(node).GetValue(idx)
    End If
  End If
End Sub
Link Posted: 26-Jan-2006 22:14
Thank you, the code above works fine.
However I still have a problem, which I forgot to mention to you before   . If I select the first item in the combo's list, then the index is -1. So basically it works fine with all the items (the index is properly found using the code above) but for the first one.
It looks like a bug to me.
Can you help ?
Link Posted: 27-Jan-2006 08:56
If you mention this portion of code:
Dim idx As Integer = m_QueryName.GetValueList(dgQueries.Selected).IndexOf(m_QueryName.GetValueList(dgQueries.Selected), m_QueryName.GetValue(dgQueries.Selected))


this portion you can make more simple:
Dim idx As Integer = m_QueryName.GetValueList(node).IndexOf(value)
Link Posted: 29-Jan-2006 22:34
Hi,
First the code you gave me is not correct:

Dim idx As Integer = m_QueryName.GetValueList(node).IndexOf(value)


There is no IndexOf overloaded function that accepts this number of argument.
It should be:

m_QueryName.GetValueList(node).IndexOf(m_QueryName.GetValueList(dgQueries.Selected), value)


Second, this is not the problem I was referring to in my post.
The problem is that if I select the first item of the lookuplist, then the index is -1 instead of being 1. However the code works fine with all other items. Therefore, I suspect this is a bug in the Flygrid.
Can you help?
Link Posted: 29-Jan-2006 22:44
I think that problem in referring to the dgQueries.Selected:

m_QueryName.GetValueList(node).IndexOf(m_QueryName.GetValueList(dgQueries.Selected), value)


May be:

m_QueryName.GetValueList(node).IndexOf(m_QueryName.GetValueList(node), value)


?

Returning of -1 means that value doesn't exists in the value list - please check/debug this (IndexOf is standard function of Array class).
Link Posted: 29-Jan-2006 22:53
fixed.
appologies, bug was in my code