This project is read-only.

How can i get cell value in dataGrid?

Nov 25, 2009 at 9:55 PM



I working with dataGrid. I'm loading data from some table. User select a row. How can i get value from first cell in selected row? (it's contain Primary Key)

Sourse code:



                    dataGrid1.DataSource = new DevAge.ComponentModel.BoundDataView(database.OpenFBSQL("select, TRIM(B.DESCR), TRIM(C.DESCR), TRIM(A.SUMM), A.INDATE from OPERATIONS A,OPER_NAMES B,OPER_KATS C WHERE A.OPER = B.ID AND B.KAT=C.ID").Tables[0].DefaultView);
                    dataGrid1.DataSource.AllowEdit = false;
                    //dataGrid1.SelectionMode = SourceGrid.GridSelectionMode.Cell;
                    dataGrid1.SelectionMode = SourceGrid.GridSelectionMode.Row;

dataGrid1.DataSource = new DevAge.ComponentModel.BoundDataView(database.OpenFBSQL("select, b.* from OPERATIONS A,OPER_NAMES B WHERE A.OPER = B.ID").Tables[0].DefaultView);

dataGrid1.DataSource.AllowEdit = false;

dataGrid1.SelectionMode = SourceGrid.GridSelectionMode.Row;

private void dataGrid1_Click(object sender, EventArgs e)
  int CurRow = dataGrid1.Selection.GetSelectionRegion().GetRowsIndex()[0];
  HOW CAN I GET VALUE from first cell?


Nov 26, 2009 at 7:33 AM

I have two solution

the first is to use cellcontext() like that :


CellContext cell = new CellContext(dataGrid1, new Position(CurRow, 1));


or you can use also this


Object[] SelectedDataRows = dataGrid.SelectedDataRows;
if (SelectedDataRows != null)
DataRowView drv = (DataRowView)(SelectedDataRows[0]);
MessageBox.Show(drv[0].ToString());// or you can use the label of the column



Nov 27, 2009 at 10:57 PM

Thank you! i'ts great! 

First solution so simple!!!