尝试在repositoryItemGridLookUpEdit1_EditValueChanged
事件中从gridview获取单元格值。但是我只得到null值然后错误显示在这一行中“对象引用未设置为对象的实例”。
如何在EditValueChanged事件中从gridview获取特定行的单元格值?
我的代码就是这个
private void repositoryItemGridLookUpEdit1_EditValueChanged(object sender, EventArgs e)
{
GridLookUpEdit LookupEdit = sender as GridLookUpEdit;
DataRowView SelectedDataRow = (DataRowView)LookupEdit.GetSelectedDataRow();
gridView1.SetFocusedRowCellValue("Description", SelectedDataRow["ProductDescription"]);
gridView1.SetFocusedRowCellValue("UoM", SelectedDataRow["UnitofMeasure"]);
gridView1.SetFocusedRowCellValue("Quantity", SelectedDataRow["DefaultQuantity"]);
gridView1.SetFocusedRowCellValue("Price", SelectedDataRow["MRPPrice"]);
gridView1.SetFocusedRowCellValue("TaxInPercentage", SelectedDataRow["Taxid1"]);
gridView1.SetFocusedRowCellValue("ProductKind", SelectedDataRow["ProductKind"]);
getdisc = LookupEdit.EditValue.ToString(); // get display value & pass to comparision to find Discound
object productkin = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["ProductDescrption"]);
string productkind = productkin.ToString(); // Error Object reference not set to instance of object
MessageBox.Show(productkind, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
帮帮我?
答案 0 :(得分:2)
正如Corak注意到的那样:获取行单元格值时出现错字错误(缺少“i”):
object productkin = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["ProductDescrption"]);
由于“ProductDescrption”列不存在,变量productkind为null。用以下内容替换此行:
object productkin = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["ProductDescription"]);