My Challenge:
I am trying to capture the selected row in a RadGridView which I would like to store in the database when the user exits the screen. When the user re-enters the screen I would like to programmatically select the row previously stored.
I set up a proof of concept using 2 Test buttons and a GridView:
Test 1 Button:
- Get the selected row
- Cast the selected row object to a string (which would be stored in the database)
- Cast the string back to an object (simulate return from the database)
- Add object to a list of objects
- Clear selected items in the grid
Test 2 Button:
- Execute the Select method on the GridView with the list of selected objects as an argument
- Check the GridView SelectedItems count
Problem:
The select method executes but nothing happens. What am I missing?
Sample Code:
private object rowObject = new object();
private List<object> rowList = new List<object>();
private void test1_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (ProjectListingGridView.SelectedItems.Count > 0)
{
var item = ProjectListingGridView.SelectedItem.ToString();
if (item != null)
{
var rowObject = (object)item;
rowList.Clear();
rowList.Add(rowObject);
}
this.ProjectListingGridView.SelectedItems.Clear();
}
}
private void test2_Click(object sender, System.Windows.RoutedEventArgs e)
{
var selectList = rowList;
try
{
ProjectListingGridView.Select(selectList);
}
catch (Exception)
{
throw;
}
var cnt = ProjectListingGridView.SelectedItems.Count;
}