2010-07-11 4 views
0

그냥 물어보고 싶습니다. ProdName, Quantity, SellingPrice 및 Total 열이있는 제품의 DataGridview가 있습니다. Quantity와 SellingPrice는 모두 ReadOnly 속성을 false로 설정합니다. 그래서 기본적으로 사용자는 런타임 중에 값을 변경할 수 있습니다. 제가 알고 싶은 것은 실제로 Quantity와 SellingPrice의 곱인 Total 열에 어떻게 값을 삽입 할 수 있습니까?DataGridView의 입력 자동 계산 - C#

모든 입력을 환영합니다. 감사합니다 :)

+0

있습니까? – codekaizen

+0

아니요, 이것은 Windows 응용 프로그램 일뿐입니다. :) – Smiley

답변

0

당신은 CellValidated 이벤트 사용할 수 있습니다이 ASP.Net은

private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e) 
{ 
    // TODO: Add proper error handling by checking for null values, 
    // using decimal.TryParse, ... 
    var row = dataGridView1.Rows[e.RowIndex]; 
    int quantity = int.Parse(row.Cells[1].Value.ToString()); 
    decimal sellingPrice = decimal.Parse(row.Cells[2].Value.ToString()); 
    row.Cells[3].Value = quantity * sellingPrice; 
} 
+0

CellValidated는 셀 값이 변경되었을 때만이 아니라 일부 UI 전용 이벤트를 포함한 여러 가지 이유로 인해 발생합니다! –