I have setup a Master-Details datagrid according to the Instructions provided by this site. I am able to get cell values of any cell on the Master grid but unable to figure out out to get any of the cell values on the details grid.
I have looked at this article:
but this article shows a sample where the child grid is added manually, where my child grid is added through databound relationships.
how can I go about getting cell values WITHOUT button clicks AND with button clicks from my detail grid that is databound?
Code Snippet:
private void button1_Click(object sender, EventArgs e) { SfDataGrid sfDataGrid = this.sfDataGrid1.GetDetailsViewGrid(2); Text.Text = GetCellValue(sfDataGrid, Convert.ToInt32(textBox2.Text), Convert.ToInt32(textBox1.Text)); } private static string GetCellValue(Syncfusion.WinForms.DataGrid.SfDataGrid dGrid, int rowIndex, int columnIndex) { string cellValue; if (columnIndex < 0) return string.Empty; var mappingName = dGrid.Columns[columnIndex].MappingName; var recordIndex = dGrid.TableControl.ResolveToRecordIndex(rowIndex); if (recordIndex < 0) return string.Empty; if (dGrid.View.TopLevelGroup != null) { var record = dGrid.View.TopLevelGroup.DisplayElements[recordIndex]; if (!record.IsRecords) return string.Empty; var data = (record as RecordEntry).Data; cellValue = (data.GetType().GetProperty(mappingName).GetValue(data, null).ToString()); } else { var record1 = dGrid.View.Records.GetItemAt(recordIndex); cellValue = (record1.GetType().GetProperty(mappingName).GetValue(record1, null).ToString()); } return cellValue; } |
(this.sfDataGrid1.DetailsViewDefinitions[0] as GridViewDefinition).DataGrid.CellClick += DataGrid_CellClick; private void DataGrid_CellClick(object sender, CellClickEventArgs e) { // Get the row index value var rowIndex = e.DataRow.RowIndex; //Get the column index value var columnIndex = e.DataColumn.ColumnIndex; //Get the cell value var cellValue = (e.OriginalSender as DetailsViewDataGrid).View.GetPropertyAccessProvider().GetValue(e.DataRow.RowData, e.DataColumn.GridColumn.MappingName); MessageBox.Show("Cell Value \t: " + cellValue + "\n" + "Row Index \t: " + rowIndex + "\n" + "Column Index \t: " + columnIndex, "Cell Value"); } |