Я пытаюсь заставить свою текущую программу принимать информацию из динамически созданного DataGridView. Мне удалось получить информацию в сетке и выполнить необходимый поиск, но теперь я действительно застрял.C# динамически беру данные из DataGridView
Я добавил столбец в datagridview, который содержит кнопку в каждой строке. То, что я хотел бы сделать, это взять значение данных из индекса столбца 1, которое находится в той же строке, что и нажатая кнопка. Смешение? В любом случае, вот код:
public void GetValues(...)
{
//Details regarding connection, querying and inserting table
.
.
.
DataGridViewButtonColumn buttonCol = new DataGridViewButtonColumn();
buttonCol.Name = "ButtonColumn";
buttonCol.HeaderText = "Select";
buttonCol.Text = "Edit";
//NB: the text won't show up on the button. Any help there either?
dataGridView1.Columns.Add(buttonCol);
dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewButtonCell button = (row.Cells["ButtonColumn"] as DataGridViewButtonCell);
}
dataGridView1.Columns["ButtonColumn"].DisplayIndex = 0;
}
void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
//Here is where I'm having the trouble. What do I put in here???
}
Спасибо за любую помощь, которую вы можете дать!
David.
Большое спасибо, очень полезно! –