將database的資料連結到DataGridView後,下一個步驟當然就是對資料做Read/Wirte的動作
這一篇簡單的說明要如何Get/Read Cell的資料
可以透過DataGridView的屬性獲取資料,程式碼如下:
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = dataGridView1.Rows[0].Cells[1].Value.ToString();
}
配合DataGridView的事件CellClick(如下圖),獲取點選的Cell資料
程式碼如下:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string strContent = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
MessageBox.Show(strContent);
}
Sample Code Download

沒有留言:
張貼留言