GridListControl: SelectedIndex not set properly

Hi,
I am running into strange event issue with GridListControl. I have multicolumn GridListControl placed inside of panel, so it displays grid-like data. To read content of the selected row, I used Grid_SelectionChanged event:

private void Grid_SelectionChanged(object sender, Syncfusion.Windows.Forms.Grid.GridSelectionChangedEventArgs e)
{
Foo(); //do things here
}
Foo() method uses myGrid.SelectedIndex and myGrid.SelectedItem properties and I expected that if user selected any row in the grid, they should be filled when event fires.
2 things look strange:
1. when user clicks on the row, Grid_SelectionChanged event fires twice.
2.first time myGrid.SelectedItem if filled but myGrid.SelectedIndex is still set to -1, which causes error in undelying method.
The second time event fires, both properties are set properly.
I used some work around to bypass logic if SelectedIndex=-1,but the question is, if Grid_SelectionChanged really fires AFTER selection happens. And why it is called twice? So far it is not that many things happening, but it may cause performance problem in the future, as we enhance the application. Should we use another event instead? Thanks for your help.
Btw, we use version 4.402, and while I can not confirm it, but it seems that the older version did not have this problem, this code is about 3 years old.

Irina






1 Reply

JJ Jisha Joy Syncfusion Team November 14, 2008 10:20 AM UTC

Hi Irina,

We appreciate your interest in Syncfusion products. The issue can be solved by checking e.Reason in SelectionChanged event.


void Grid_SelectionChanged(object sender, Syncfusion.Windows.Forms.Grid.GridSelectionChangedEventArgs e)
{

if (e.Reason == Syncfusion.Windows.Forms.Grid.GridSelectionReason.MouseUp)
{
Console.WriteLine("Fired" + i.ToString());
Console.WriteLine(this.gridListControl2.SelectedIndex.ToString());
}
}

Please let me know if this helps.

Regards,
Jisha


Loader.
Up arrow icon