我有两种形式: 首先是listview。双击raw时,行中的值将转换为第二种形式的texbox。代码是下一个:
public void listView1_DoubleClick(object sender, EventArgs e)
{
int index = listView1.FocusedItem.Index;
Form2 newForm = new Form2();
newForm.H_id = listView1.Items[index].Text;
newForm.Serie = listView1.Items[index].SubItems[1].Text;
newForm.Numar = listView1.Items[index].SubItems[2].Text;
newForm.Partener = listView1.Items[index].SubItems[3].Text;
newForm.Data = Convert.ToDateTime(listView1.Items[index].SubItems[4].Text);
newForm.Show();
我想用datagridview做同样的事情。我怎么办?
答案 0 :(得分:0)
希望帮助你:D
private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
int index = e.RowIndex;
Form2 newForm = new Form2();
newForm.H_id = dataGridView.Rows[index].Cells[0].Value;
newForm.Serie = dataGridView.Rows[index].Cells[1].Value;
newForm.Numar = dataGridView.Rows[index].Cells[2].Value;
newForm.Partener = dataGridView.Rows[index].Cells[3].Value;
newForm.Data = Convert.ToDateTime(dataGridView.Rows[index].Cells[4].Value);
newForm.Show();
}
答案 1 :(得分:0)
您可以使用CellDoubleClick event。如果要选择完整行集SelectionMode属性为DataGridViewSelectionMode.FullRowSelect。