I have written this function to preselect a Country in Data Grid, and it works, but the Data Grid does not automatically scrolls to the selected record. Can somebody help and tell me which Method or Property can handle this.
public void preSelectRecord() { DataRecord records; for (int i = 0; i < dataGridCountry.Records.Count; i++) { records = (DataRecord)dataGridCountry.Records[i]; if (records.Cells[1].Value.ToString() == "US") { records.IsSelected = true; records.IsActive = true; }
} }
Regards Arta!
:-) it works, thanks a lot, and have a nice day.
Arta.
Another option is always to scroll down to the last record first and then go back up to the wanted record.
dataGridCountry.ExecuteCommand(DataPresenterCommands.RecordLastOverall);
foreach(..)
{
...
}
Arta,
If the record is out of view and its index is greater than the ones that are currently in view ( for example - the record index is 100 and you can see from 1 to 10 ) then you will need to adjust the records so that the found record in first in display. You can use DataPresenterCommands to scroll records up and down, one page up or down, etc. like this for example:
...BringRecordIntoView(dr);
dr.IsActive = true;
dataGridCountry.ExecuteCommand(DataPresenterCommands.RecordPageAbove);
If the other case ( the record index is less than the ones in view ) the record will be displayed first.
Hope this helps,
Alex.
Hi Alex,
Thanks a lot for the fast Reply, it works, but the selected record is not the first Record in the DataGrid.I will try to fix by myself.
Hello Arta,
Please test the following code snipper and let me know if it does the trick in your scenario?
public void preSelectRecord() { foreach (DataRecord dr in dataGridCountry.Records) { if (dr.Cells[1].Value.ToString() == "US") { dataGridCountry.BringRecordIntoView(dr); }