How do I programmatically select, highlight and scroll into view a row in a GridGroupingControl? I have a combobox that uses the same datasource as the grid; when user selects an item in the combo box, I want the grid to scroll to that record. The user may have sorted the grid rows using any of its 5 columns.
Previous threads have addressed similar questions, but noe of the suggestions seem to work for me.
Using version 3.0.1.1.
--Van Baker
AD
Administrator
Syncfusion Team
April 30, 2005 01:43 AM UTC
Try code like this.
//someRecord is the Record object you want to select and scroll in view
this.gridGroupingControl1.Table.CurrentRecord = someRecord;
someRecord.SetSelected(true);
VB
vbaker
May 2, 2005 02:54 PM UTC
To get the desired record based on user selection from the combobox, I am using this:
int r = this.gridGroupingControl1.Table.PrimaryKeySortedRecords.FindRecord(this.combobox.SelectedValue);
Syncfusion.Grouping.Record someRecord = gridGroupingControl1.Table.Records[r];
But, unless the grid is sorted by the column containing the primary key, the wrong record is returned. How can I get the correct record even if the user sorts the grid by a different column?
--Van Baker
>Try code like this.
>
>//someRecord is the Record object you want to select and scroll in view
>this.gridGroupingControl1.Table.CurrentRecord = someRecord;
>someRecord.SetSelected(true);
>
AD
Administrator
Syncfusion Team
May 2, 2005 02:59 PM UTC
If the combobox is unsorted, try using
Syncfusion.Grouping.Record someRecord =
this.gridGroupingControl1.Table.UnsortedRecords[this.combobox.SelectedValue];
AD
Administrator
Syncfusion Team
May 2, 2005 03:56 PM UTC
Did you mean:
this.gridGroupingControl1.Table.UnsortedRecords[this.combobox.SelectedIndex];
(Since SelectedValue is the primary key, not the item index)?
Anyway, that works, except I had to add a call to
this.gridGroupingControl1.TableControl.ScrollCellInView()
in order to get the grid to scroll to the selected row if is not already visible. Also, sometimes, even though it highlights the correct row, it doesn''t always scroll it into view, even with the added ScrollCellInView() call. Finally, how do I get the grid to un-highlight a selection after a new selection is made programmatically?
Thanks,
Van Baker
>If the combobox is unsorted, try using
>
>Syncfusion.Grouping.Record someRecord =
>this.gridGroupingControl1.Table.UnsortedRecords[this.combobox.SelectedValue];
>
AD
Administrator
Syncfusion Team
May 2, 2005 04:14 PM UTC
If you know the record whose selection you want to clear, you can use:
someRecord.SetSelected(false);
If you want to clear all records, try
this.gridGroupingControl1.Table.SelectedRecords.Clear();
VB
vbaker
May 2, 2005 04:54 PM UTC
Clay, I do appreciate your assistance.
This works well except for one minor problem. Sometimes the highlighted row does not quite scroll into view after ScrollCellInView() is called. If r is the index of the record I want to be visible, I am calling it as follows:
this.gridGroupingControl1.TableControl.ScrollCellinView(r, this.gridGroupingControl1.TableControl.LeftColIndex);
Usually, the selected row scrolls into view. Sometimes, however, even though the grid scrolls, it does not scroll quite enough, falling short of the selected row by about 3 rows.
Is there a way to fix this?
Thanks,
Van Baker
>If you know the record whose selection you want to clear, you can use:
>
>someRecord.SetSelected(false);
>
>
>If you want to clear all records, try
>
>this.gridGroupingControl1.Table.SelectedRecords.Clear();
>
AD
Administrator
Syncfusion Team
May 2, 2005 05:09 PM UTC
Just using code like this in a button handler scrolls the 17th record into view and selects it for me.
Record someRecord = this.gridGroupingControl1.Table.UnsortedRecords[17];
this.gridGroupingControl1.Table.CurrentRecord = someRecord;
someRecord.SetSelected(true);
But if that does not work for you, try computing r in this manner to see if it works better.
int r = this.gridGroupingControl1.Table.DisplayElements.IndexOf(someRecord);
There is also a method, this.gridGroupingControl1.TableControl.ScrollInView, where you can pass the record and not have to get an index if that works better for you.
VB
vbaker
May 2, 2005 05:45 PM UTC
Thank You! ScrollInView(rec) did the trick. Odd how passing the index does not always work, but I''ll gladly stick with the way that does work.
--Van Baker
>Just using code like this in a button handler scrolls the 17th record into view and selects it for me.
>
>Record someRecord = this.gridGroupingControl1.Table.UnsortedRecords[17];
>this.gridGroupingControl1.Table.CurrentRecord = someRecord;
>someRecord.SetSelected(true);
>
>
>But if that does not work for you, try computing r in this manner to see if it works better.
>
>int r = this.gridGroupingControl1.Table.DisplayElements.IndexOf(someRecord);
>
>
>There is also a method, this.gridGroupingControl1.TableControl.ScrollInView, where you can pass the record and not have to get an index if that works better for you.
>
>