2014-03-26 28 views
0

請問如何在標籤或文本框中顯示數據網格視圖的行號,以便能夠在更新或刪除表中使用它。使用datagridview更新表

我嘗試以下,但是當我在數據網格單擊它什麼也不顯示視圖細胞

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) 
{ 
    int rowIndex = e.RowIndex; 
    DataGridViewRow row = dataGridView1.Rows[rowIndex]; 
    textBox9.Text = dataGridView1.Rows[0].Cells[1].Value.ToString();  
} 
+0

你能在SQL中使用序列指令來自動生成連續的行號?只是好奇。 –

回答

0

我用這個:

private void tableConteudo_CellClick(object sender, DataGridViewCellEventArgs e) 
    { 
     if (e.RowIndex != -1) 
     { 
      _myObjectVar = (MyObject)table1.Rows[e.RowIndex].DataBoundItem; 
     } 
    } 

所以,而是採用了CellContentClick,你可以使用CellClick事件。

0

試試這個,

私人無效dataGridView1_CellContentClick(對象發件人,DataGridViewCellEventArgs E) {

textBox9.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();  

}