devexpress显示数据表格.行和单元格
本文关键字:单元格 表格 数据表 显示 数据 devexpress | 更新日期: 2023-09-27 18:11:24
目前我一直在使用Devexpress Datagridview。因此,我需要将下面的代码转换为它的Devexpress Datagridview等效:
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)。
我假设您正在尝试捕获基于某个偶数的行数据,您在问题中省略了该偶数。假设您正在使用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
};
如果你正在使用数据表…考虑切换到域对象。这并不总是最好的方法,但是有很多优点。
我认为这是一个明确的代码,以获取数据在gridview行devexpress在XtragridControl.
if (gridView1.RowCount >= 1)
{
List<PurchaseChild> purchaseChild = new List<PurchaseChild>();
PurchaseParent purchaseParent = new PurchaseParent()
{
PurchaseDate = Convert.ToDateTime(txtPurchaseDate.EditValue),
PurchaseInvoice = txtInvoice.EditValue.ToString(),
CompanyInvoice = txtCompanyInvoice.EditValue.ToString(),
SupplyerId = cmbSupplyer.EditValue.ToString(),
DelivaryBy = txtDelivaryBy.EditValue.ToString(),
CreateBy = Settings.Default.UserName,
CreateDate = DateTime.Now,
PcName = txtComputerName.EditValue.ToString()
};
for (int i = 0; i < gridView1.DataRowCount; i++)
{
purchaseChild.Add(new PurchaseChild()
{
PurchaseInvoice = txtInvoice.EditValue.ToString(),
ProductCode = gridView1.GetRowCellValue(i, "ProductCode").ToString(),
Qty = Convert.ToInt16(gridView1.GetRowCellValue(i, "Qty")),
ProductPrice = Convert.ToInt16(gridView1.GetRowCellValue(i, "ProductPrice")),
SellingPrice = Convert.ToInt16(gridView1.GetRowCellValue(i, "SellingPrice")),
DiscountPrice = Convert.ToInt16(gridView1.GetRowCellValue(i, "DiscountPrice") == null ? 0 : gridView1.GetRowCellValue(i, "DiscountPrice")),
DiscountAmount = Convert.ToInt16(gridView1.GetRowCellValue(i, "DiscountPrice") == null ? 0 : gridView1.GetRowCellValue(i, "DiscountAmount")),
TotalAmount = Convert.ToInt16(gridView1.GetRowCellValue(i, "Qty")) * Convert.ToInt16(gridView1.GetRowCellValue(i, "ProductPrice"))
});
}