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: 17-Feb-2006 03:49
Hi,
This is exactely what I've done (actually i've copied and paste the code from the help file). The only difference is that I cast the result of GetService to IDropDownListService as I've got option Strict On.
But still the result is nothing...
Link Posted: 17-Feb-2006 05:01
I don't think so,
here is code from FlyGrid.Net Help: (see the comments in the code)
[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 dgParams.NodeCellChange
    If (index = 0) Then ' if column is a first column
      'cast FlyGrid as IServiceProvider
      Dim sp As IServiceProvider = CType(Me.flyGrid, IServiceProvider)
      ' get a IDropDownListService instance
      Dim idls As NineRays.Windows.Forms.Grids.IDropDownListService =         sp.GetService(me.flyGrid.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: 17-Feb-2006 05:13
Yes that's the same as my code (I've got the comments too as I got it from the help file).
The only difference is:

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


I'm casting to IDropDownListService to avoid compilation error.

And when I debug, idls is always Nothing.

Also my column is LookupListColumn instead of DropDownList, not sure if it makes any difference....
Link Posted: 17-Feb-2006 06:05
But why you cast returned by sp.GetService result to IDropDownListservice?

Dim idls As NineRays.Windows.Forms.Grids.IDropDownListService = sp.GetService(me.dgParams.GetType().Assembly.GetType("NineRays.Windows.Forms.Grids.IDropDownListService"))

works fine and doesn't generate build errors.

but I've tried to use following code, and this code also works fine:

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


Test this part of code :

Me.dgParams.GetType().Assembly.GetType("NineRays.Windows.Forms.Grids.IDropDownListService")

if this part returns null it means that your app can't resolve assembly and find NineRays.Windows.Forms.Grids.IDropDownListService type.
This code extract assembly from Me.dgParams type (in this case it NineRays.FlyGrid.dll), if Me.dgParams has another type (inheritor from FlyGrid.Net) you can extract assembly from another instance (following code extract assembly from node):

node.GetType().Assembly.GetType("NineRays.Windows.Forms.Grids.IDropDownListService")
Link Posted: 17-Feb-2006 06:27
But why you cast returned by sp.GetService result to IDropDownListservice?


Because GetService returns an Object and idls expects IDropDownListService type. I've got the option Strict On so it generates an error.

Anyway.
This :

Me.dgParams.GetType().Assembly.GetType("NineRays.Windows.Forms.Grids.IDropDownListService")


returns Nothing for me. Probably as you said because my grid is inherited from Flygrid. So instead I've used:

node.GetType().Assembly.GetType("NineRays.Windows.Forms.Grids.IDropDownListService")


and now it works fine. The Id is found ok.  

However now there is a bug I didn't have before:  
If I select a value in my list, the value is displayed properly in the cell.
Then I delete the row. Now I select again a value in the list, but it is not shown anymore in the cell, whatever the value is ! Looks like a bug or is it related to the fact I get IDropDownLIstService from Node ?
Link Posted: 17-Feb-2006 08:28
If I select a value in my list, the value is displayed properly in the cell.
Then I delete the row. Now I select again a value in the list, but it is not shown anymore in the cell, whatever the value is ! Looks like a bug or is it related to the fact I get IDropDownLIstService from Node ?


Please redownload Flygrid.Net, this incorrectness is fixed.
Link Posted: 01-Mar-2006 02:21
It works better, but still not perfect  
If you select the value in the list by double clicking on the node (instead of selecting the value by expanding the list and choosing a value), then the returned index is -1. This is a bug I believe.
Link Posted: 02-Mar-2006 11:55
If you select the value in the list by double clicking on the node.

But this task is not related to IDropDownLIstService.
In this case column call Column.IncrementValue or if Shift to choose next value in the list is pressed - Column.DecrementValue to choose previous value in the list.
You can override these methods in the class-inheritor or analyze current value.
Link Posted: 02-Mar-2006 22:16
[quote="NineRays"]
But this task is not related to IDropDownLIstService.

Yes, it is. As I said, if you select a value in the dropdownlist, it returns correct index. But if you double click on the cell, so that the first item in the dropdownlist gets selected, then the index returned is -1. This is clearly related to IDropDownLIstService.
Link Posted: 03-Mar-2006 14:05
Can you provide us with a sample - probably problem related to the duplicated values in dropdownlist.