This question is locked. New answers and comments are not allowed.
Hello,
I have unique grid that is using SL lightweight datatable to populate cells in my RadGridView. I have to use it because my grid is dynamically created as per users preference about number of rows and columns.
I have to bind blank rows initially and later user populate the data inside the cells using separate form view. When user select cell I have to fetch data from DB and populate that on form view. In order to do so I need to know row index and column index of selected cell.
I can find column index easily but problem lies in row index because data in each cell is empty string and RadGridview is trying to lookup data based on datacontext as below:
I have unique grid that is using SL lightweight datatable to populate cells in my RadGridView. I have to use it because my grid is dynamically created as per users preference about number of rows and columns.
I have to bind blank rows initially and later user populate the data inside the cells using separate form view. When user select cell I have to fetch data from DB and populate that on form view. In order to do so I need to know row index and column index of selected cell.
I can find column index easily but problem lies in row index because data in each cell is empty string and RadGridview is trying to lookup data based on datacontext as below:
RadGridView1.Items.IndexOf(RadGridView1.CurrentCell)here is my Xaml: <telerik:RadGridView x:Name="RadGridView1" AutoExpandGroups="True" RowIndicatorVisibility="Collapsed" Grid.Row="1" SelectionUnit="FullRow" CurrentCellChanged="RadGridView1_CurrentCellChanged" SelectedCellsChanged="RadGridView1_SelectedCellsChanged" SelectionChanged="RadGridView1_SelectionChanged" />
Here is my codebehind:
DataTable table = null; public MainPage() { InitializeComponent(); Random rnd = new Random(); table = new DataTable(); for (int i = 0; i <= 5; i++) { var coln = "col " + i.ToString(); table.Columns.Add(new DataColumn() { ColumnName = coln, DataType = typeof(string) }); } for (var r = 0; r < 10; r++) { DataRow row = new DataRow(); for (int c = 0; c <= 5; c++) { var coln = "col " + c.ToString(); row[coln] = "Hello"; } table.Rows.Add(row); } RadGridView1.ItemsSource = table.ToList(); } private void RadGridView1_CurrentCellChanged(object sender, Telerik.Windows.Controls.GridViewCurrentCellChangedEventArgs e) { txtitems.Text = "you selected Row " + RadGridView1.Items.IndexOf(RadGridView1.CurrentCell) + " Column " + e.NewCell.Column.DisplayIndex; } private void RadGridView1_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e) { } private void RadGridView1_SelectedCellsChanged(object sender, Telerik.Windows.Controls.GridView.GridViewSelectedCellsChangedEventArgs e) { //txtitems.Text = "you selected Row " + RadGridView1.Items.IndexOf(e.AddedCells[0].Item) // + " Column " + e.AddedCells[0].Column.DisplayIndex; }
I tried using both types of selectionunit (cell,fullrow), but none worked.
Is there anyway to get selected row index using some other event? I go through documentation but no help so far.
Thanks in advance.
-Vedant
NOTE: you need to get data.cs and dynamic.cs classes in your project from here