1. 程式人生 > >c# dev gridview 給指定單元格賦值

c# dev gridview 給指定單元格賦值

 下面是我要通過修改單元格中單價,數量,來自動生成合價的資料

private void gridView1_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {          
                int i = e.RowHandle; //行數,千萬別用for迴圈來遍歷gridview的行數
                object sl = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SL"); //獲取指定列SL資料
                object dj = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DJ"); //獲取指定列DJ資料


                if (sl != System.DBNull.Value && dj != System.DBNull.Value)    //判讀object型別是否為空
                {
                    int a = Convert.ToInt32(sl);
                    Decimal b = Convert.ToDecimal(dj);                 
                    this.gridView1.GetDataRow(i)["HJ"] = (a*b).ToString();
                }      
        }