I have a datagridview that is a full row select. How would I grab the data from only a certain cell no matter what cell in the row was clicked on since it highlights the ent
dataGridView1.SelectedRows[0].Cells[0].Value;
You can do like this:
private void datagridview1_SelectionChanged(object sender, EventArgs e)
{
if (datagridview1.SelectedCells.Count > 0)
{
int selectedrowindex = datagridview1.SelectedCells[0].RowIndex;
DataGridViewRow selectedRow = datagridview1.Rows[selectedrowindex];
string a = Convert.ToString(selectedRow.Cells["enter column name"].Value);
}
}
this get me the text value of exact cell in data grid view
private void dataGridView_SelectionChanged(object sender, EventArgs e)
{
label1.Text = dataGridView.CurrentRow.Cells[#].Value.ToString();
}
you can see it in label and change # wih the index of the exact cell you want
Just Use: dataGridView1.CurrentCell.Value.ToString()
private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
MessageBox.Show(dataGridView1.CurrentCell.Value.ToString());
}
or
// dataGrid1.Rows[yourRowIndex ].Cells[yourColumnIndex].Value.ToString()
//Example1:yourRowIndex=dataGridView1.CurrentRow.Index (from selectedRow );
dataGrid1.Rows[dataGridView1.CurrentRow.Index].Cells[2].Value.ToString()
//Example2:yourRowIndex=3,yourColumnIndex=2 (select by programmatically )
dataGrid1.Rows[3].Cells[2].Value.ToString()
DataGridView.CurrentRow.Cells[n]
See: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentrow.aspx
I just want to point out, you can use .selectedindex to make it a little cleaner
string value = gridview.Rows[gridview.SelectedIndex].Cells[1].Text.ToString();