this.dataGridView1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(dataGridView1_KeyPress);
void dataGridView1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
throw new System.NotImplementedException();
if (e.KeyChar == 13)
{
for (int ix = 0; ix < dataGridView1.Rows.Count; ix++)
{
dataGridView1.Rows[ix].Cells[4].Value = Convert.ToString(Convert.ToInt32(dataGridView1.Rows[ix].Cells[1].Value) + Convert.ToInt32(dataGridView1.Rows[ix].Cells[2].Value) + Convert.ToInt32(dataGridView1.Rows[ix].Cells[3].Value));
}
}
}
Page.CS Code (C#)
private void button1_Click_1(object sender, EventArgs e)
{
DataGridViewRow dgvRow = new DataGridViewRow();
DataGridViewCell dgvCell;
dgvCell = new DataGridViewTextBoxCell();
dgvCell.Value = "คอมลัม1";
dgvRow.Cells.Add(dgvCell);
dgvCell = new DataGridViewTextBoxCell();
dgvCell.Value = "คอมลัม2";
dgvRow.Cells.Add(dgvCell);
dgvCell = new DataGridViewTextBoxCell();
dgvCell.Value = "คอมลัม3";
dgvRow.Cells.Add(dgvCell);
dataGridView1.Rows.Add(dgvRow);
}
Date :
2011-04-26 17:02:32
By :
hamzter
No. 3
Guest
vb.net na krab.
please!!!!!!.
Date :
2011-04-27 14:39:05
By :
xmen
No. 4
Guest
Code (VB.NET)
Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
If e.ColumnIndex.ToString = 3 Then
v = CInt(DataGridView1.Rows(e.RowIndex).Cells("A").Value) + CInt(DataGridView1.Rows(e.RowIndex).Cells("B").Value) + CInt(DataGridView1.Rows(e.RowIndex).Cells("C").Value)
DataGridView1.Rows(e.RowIndex).Cells("D").Value = v
End If
End Sub
ผมเรียกใช้การกด enter แต่พอใช้งานจริงต้องไปกด tab เอาอ่ะคับรบกวนแนะนำด้วยคับ