Hi,
When filtering is applied, how can I correlate the ranges reported by GetSelectedRanges() back to my data?
Say I have three items in my data source: 'one', 'two', 'three'. Suppose the user uses the filter bar to filter out all but 'three'. If they select 'three' it is reported as a range of [1,1]. But what I really want is [3,3] so I can correlate to the actual data they've selected.
What facility is provided to translate this range to the equivalent range assuming no filtering?
Thanks
SD
Sarathi D
Syncfusion Team
August 25, 2007 12:42 AM UTC
Hi ,
This is a default behavior of the filtering functionality in our grid. If you want to keep the index of the selected ranges in a grid then you need to follow the below steps to resolve this.
1) To disable default functionality of the filter bar in a grid.
2) Add an extra row header for a grid using Model.Rows.HeaderCount property.
3) Change the celltype of the extra header cell to Combox celltype and set its DataSource,DisplayMember and ValueMember property using the QueryCellInfo event.
4) Hide the non matching rows of the grid depending on the SelectedValue of the Extra header combox cell in CurrentCellCloseDropDown event of the grid using the SetRange method.
Please try this and let us know if you have any other questions regarding this issue. We will be glad to assist you.
Best regards,
Sarathi
KB
Kent Boogaart
August 27, 2007 12:34 AM UTC
I'm confused. If there is no way to correlate selected ranges back to the data source, how is filtering even used in a real-world app?
All I want to do is something like:
_grid.DataSource = customers;
//later on
List selectedCustomers = new ...;
foreach (GridRangeInfo range in _grid.Selections)
{
//how do I get the Customer here?
selectedCustomers.Add(???);
}
Thanks
SD
Sarathi D
Syncfusion Team
August 29, 2007 01:30 AM UTC
Hi,
We currently looking into this issue. I will update the status of the issue within one business day.
Sorry for the inconvenience.
Regards,
Sarathi
KB
Kent Boogaart
August 29, 2007 02:08 AM UTC
Guess I'll answer my own question then for others struggling with the same problem.
Firstly, you might think you could use:
_grid.Binder.RowIndexToListManagerPosition(index)
to translate the index to an index in the underlying data source. Indeed, that is exactly what this method is supposed to do. But it doesn't. No idea why.
To work around this, I access the DataView directly:
DataTable dataTable = _grid.DataSource as DataTable;
//i is just an index reported by a range from GetSelectedRanges()
int translatedIndex = _grid.Binder.RowIndexToPosition(i);
DataRow dataRow = dataTable.DefaultView[translatedIndex].Row;
HTH
KB
Kent Boogaart
August 29, 2007 02:09 AM UTC
Sorry Sarathi,
I saw your reply after posting mine above. Let me know if you need more info.
SD
Sarathi D
Syncfusion Team
August 29, 2007 08:53 PM UTC
Hi Lcd,
Glad that you have solved the issue. Thank you for sharing the information with us.
Please let me know if you have any further queries.
Regards,
Sarathi
KB
Kent Boogaart
August 30, 2007 12:44 AM UTC
Hi Sarathi,
I'm interested to hear whether there are plans to fix RowIndexToListManagerPosition, or whether I'm just mistaken about its purpose. It seems to me it should facilitate exactly the functionality I was after, but doesn't.
Thanks
SD
Sarathi D
Syncfusion Team
September 11, 2007 01:01 AM UTC
Hi Lcd,
Can you please create a direct trac incident in this regard since this is suspected to be a defect and we can discuss further on this issue.
Please specify the Forum Id in the subject line of the incident.
Regards,
Sarathi