Datagrid cell Value
-
I'm making use of a datagrid, How do you get the current value of a specific cell (row 0, col 0) after the user sorts by clicking on the columnheader? This is what I tried using the MouseUp event but I seem to be getting the value of the cell before the sort. private void dGrdFamily_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { //if left mouse is clicked if(e.Button == MouseButtons.Left) { Point pt = new Point(e.X, e.Y); DataGrid.HitTestInfo hti = this.dGrdFamily.HitTest(pt); if(hti.Type == DataGrid.HitTestType.ColumnHeader) { this.textBox2.Text = this.dGrdFamily[0,0].ToString(); } } }
-
I'm making use of a datagrid, How do you get the current value of a specific cell (row 0, col 0) after the user sorts by clicking on the columnheader? This is what I tried using the MouseUp event but I seem to be getting the value of the cell before the sort. private void dGrdFamily_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { //if left mouse is clicked if(e.Button == MouseButtons.Left) { Point pt = new Point(e.X, e.Y); DataGrid.HitTestInfo hti = this.dGrdFamily.HitTest(pt); if(hti.Type == DataGrid.HitTestType.ColumnHeader) { this.textBox2.Text = this.dGrdFamily[0,0].ToString(); } } }
If the DataSource is a DataTable you can use private DataRow GetDataRowAt(int index) { DataRow dataRow = null; CurrencyManager currencyManager = null; currencyManager = (CurrencyManager)this.BindingContext[this.dataTable]; if ( currencyManager != null ) { dataRow = ((DataRowView)currencyManager.List[index]).Row; } return dataRow; } Live Life King Size Alomgir Miah
-
If the DataSource is a DataTable you can use private DataRow GetDataRowAt(int index) { DataRow dataRow = null; CurrencyManager currencyManager = null; currencyManager = (CurrencyManager)this.BindingContext[this.dataTable]; if ( currencyManager != null ) { dataRow = ((DataRowView)currencyManager.List[index]).Row; } return dataRow; } Live Life King Size Alomgir Miah
Hi: Thanks for your help. I tried your suggestion but I came across the same problem. It seems like the MouseUp event that I'm using may not be the best event to use in this case. It seems like it is obtaining the row value prior to the actual sort of the datagrid values. Do you know of any event that I can implement to notify me when a change has occurred in a cell/row value (not change in row index)??
-
I'm making use of a datagrid, How do you get the current value of a specific cell (row 0, col 0) after the user sorts by clicking on the columnheader? This is what I tried using the MouseUp event but I seem to be getting the value of the cell before the sort. private void dGrdFamily_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { //if left mouse is clicked if(e.Button == MouseButtons.Left) { Point pt = new Point(e.X, e.Y); DataGrid.HitTestInfo hti = this.dGrdFamily.HitTest(pt); if(hti.Type == DataGrid.HitTestType.ColumnHeader) { this.textBox2.Text = this.dGrdFamily[0,0].ToString(); } } }
Use the datagrid.Refresh() function...