2016-10-03 96 views
1

目前我一直在使用Devexpress Datagridview。所以,我需要下面的代碼轉換成其的DevExpress的DataGridView相當於:devexpress gridView.Rows和單元格?

 int id = e.RowIndex; 
     DataGridViewRow row = dgvproductMenu.Rows[id]; 


     if (dgvproductMenu.Columns[e.ColumnIndex].Name == "Update") 
     { 
      product ObjP = new product 
      { 
       Product_id = row.Cells[2].Value.ToString(), 
       Name = row.Cells[3].Value.ToString(), 
       Description = row.Cells[4].Value.ToString(), 
       Price = Convert.ToDouble(row.Cells[5].Value), 
       Uom = row.Cells[6].Value.ToString(), 
       Quantity =Convert.ToInt32(row.Cells[7].Value.ToString()), 
       Tax = row.Cells[8].Value.ToString() 
      }; 
      frmAddProduct fm = new frmAddProduct(ObjP); 
      fm.ShowDialog(); 
      this.fillGrid(); 

我想用的DevExpress擴展(GridView控件)做到這一點。

+0

爲什麼不考慮devexpress文檔? – Rahul

+0

DataRow row = gdvInvoiceSummary.GetDataRow(gdvInvoiceSummary.GetSelectedRows()[0]); 如果(e.Button.Caption == 「更新」) { 帳單摘要OBJ =新帳單摘要 { //客戶名稱=行。 }; frmAddinvoice fm = new frmAddinvoice(); fm.ShowDialog(); } – RifathMohamed

+0

也許從獲取和設置單元值文檔開始:https://documentation.devexpress.com/#windowsforms/CustomDocument753 – Brendon

回答

0

我假設你試圖捕獲基於某個偶數的行數據,這是你從問題中省略的。假設您使用的是POCO/Domain Object,那麼需要引入綁定源並使用綁定源的.Current屬性來確定突出顯示的行。或者,如果您對此設置了死鎖,則網格視圖的.GetRow(i)事件將返回第i行中的對象。

從這裏,你可以簡單地強制轉換爲你的POCO:

MyClrObject mo = (MyClrObject)bindSourceClr.Current; 

MyClrObject mo = (MyClrObject)gridView1.GetRow(gridView1.FocusedRowHandle); 

我想這也是對你的後續清潔方法,你在哪裏提取列值。相反,假設有關列順序什麼的,你可以使用智能感知得到確切的性質:

product ObjP = new product 
{ 
    Product_id = MyClrObject.ProductId, 
    Name = MyClrObject.Name, 
    Description = MyClrObject.Description 
}; 

如果您正在使用數據表...考慮切換到域對象。這並不總是最好的方式,但有許多優點。