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: 13-Feb-2006 05:37
I'm having problem again with this.

in my NodeCellChange event I still do the following:

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


which returns index of selected value in combobox. But the problem is when there are multiple items with the SAME value. Then index returned is the one of the first item in the list that corresponds to 'value'.

How can I return the right index of the selected item ?

Thanks
Link Posted: 13-Feb-2006 06:57
Hmmm, lookuplist especially designed to hold unique values,
may be you can use custom dropdowns for these purposes?
In this case you can know index of item in the dropdown.
See the Grid Stylizing sample for the CustomDropdown column code.
Link Posted: 13-Feb-2006 22:12
What about DropDownList Column ? Is it also designed to hold unique values or is there a way to know the index of the selected item ?

Actually I don't understand why the fact that it has multiple same values stops us from getting the right selected id in the lookuplist ? There should be a way to know the index of the selected item, regardless its value, don't you think ? Maybe it wouldn't be too hard for you to add a simple function or property tto the library which would do that?  


See the Grid Stylizing sample for the CustomDropdown column code.

I don't see where you get the index of selected item in this sample ??

Thanks
Link Posted: 14-Feb-2006 01:22
[quote="graphicsxp"]What about DropDownList Column ? Is it also designed to hold unique values or is there a way to know the index of the selected item ?

No, you can manage data in the dropdown as you want and access to the control in the dropdown.

Actually I don't understand why the fact that it has multiple same values stops us from getting the right selected id in the lookuplist ? There should be a way to know the index of the selected item, regardless its value, don't you think ? Maybe it wouldn't be too hard for you to add a simple function or property tto the library which would do that?  


Please send us () a sample that describe problem, We'll try to find solution for it.
Link Posted: 14-Feb-2006 01:28
Thanks for your help.
I don't need to write a sample, as you already got one in your vb.net samples on this forum. If you use the one that fill up a dropdown list or a lookuplist column. Then I need the index of the selected item in the list, obviously not based on value otherwise it returns the index of the first matching value in the list.
Link Posted: 14-Feb-2006 06:20
In the nearest version FlyGrid, it will be possible, here is a code that you can use to determine selectedindex of value in the dropdown list:
[VB.Net]
Private Sub dgParams_NodeCellChange(ByVal sender As Object, ByVal node As NineRays.Windows.Forms.Data.NodeBase, ByVal index As Integer, ByVal value As Object) Handles dgParams.NodeCellChange
    If (index = 0) Then
      'cast FlyGrid as IServiceProvider
      Dim sp As IServiceProvider = CType(Me.dgParams, IServiceProvider)
      ' get a IDropDownListService instance
      Dim idls As NineRays.Windows.Forms.Grids.IDropDownListService = _
        sp.GetService(me.dgParams.GetType().Assembly.GetType("NineRays.Windows.Forms.Grids.IDropDownListService"))
      If (Not idls Is Nothing) Then 'if it supported - receive currently selected index
        Dim selectedIndex As Integer = idls.SelectedIndex
        'output to diagnostics console    
        System.Diagnostics.Debug.WriteLine("Selected Index is " + selectedIndex.ToString())
        'here place your code....
      End If
    End If
  End Sub
Link Posted: 14-Feb-2006 06:34
Thanks a lot for your support, you are really efficient !

I haven't tried the code as NineRays.Windows.Forms.Grids.IDropDownListService is not recognized in version 1.3.

Will that work with lookuplist columns as well ?
Link Posted: 14-Feb-2006 06:39
I haven't tried the code as NineRays.Windows.Forms.Grids.IDropDownListService is not recognized in version 1.3.

NineRays.Windows.Forms.Grids.IDropDownListService will supported in the nearest FlyGrid.Net update (end of this week).

Will that work with lookuplist columns as well ?

Yes.
Link Posted: 16-Feb-2006 22:54
Hi,
I've tried new version of Flygrid, and now the code compiles.

However the following lines returns always nothing :

Dim idls As NineRays.Windows.Forms.Grids.IDropDownListService = _
              CType(sp.GetService(dgQueries.GetType().Assembly.GetType("NineRays.Windows.Forms.Grids.IDropDownListService")), IDropDownListService)


what's wrong ?

Thank you
Link Posted: 17-Feb-2006 03:42
Please attentively read the code provided (this sample you can find in the FlyGrid.Net documentation in the IDropDownListService descriptions):
1. Firstly - convert FlyGrid to IServiceProvider
2. use extracted IserviceProvider instance to call GetService
3. as argument of GetService method use type of IDropDownListService:
dgQueries.GetType().Assembly.GetType("NineRays.Windows.Forms.Grids.IDropDownListService")