取LookupEdit组件数据源当前资料行某字段的值
取LookupEdit组件数据源当前资料行某字段的值
解决方案示例:
源码:
源码下载:
问题描述:
此窗体中的项目列绑定了LookupEdit组件,如何调用LookupEdit的事件,当LookupEdit的值发生变化,其取值列随之变化?就是(第四列的值是根据第二列的值发生变化的)
此窗体中的项目列绑定了LookupEdit组件,如何调用LookupEdit的事件,当LookupEdit的值发生变化,其取值列随之变化?就是(第四列的值是根据第二列的值发生变化的)
解决方案示例:
源码:
C# Code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 产品数据
/// </summary>
private DataTable StockData
{
get
{
DataTable dt = new DataTable();
dt.Columns.Add("StockCode", typeof(string));
dt.Columns.Add("StockName", typeof(string));
dt.Columns.Add("Price", typeof(decimal));
dt.Rows.Add(new object[] { "CS2.0", "开发框架-V2.0", 100.11 });
dt.Rows.Add(new object[] { "CS2.2", "开发框架-V2.2", 200.22 });
dt.Rows.Add(new object[] { "CS3.0", "开发框架-V3.0", 300.33 });
dt.AcceptChanges();
return dt;
}
}
/// <summary>
/// 销售订单明细数据
/// </summary>
private DataTable SaleDetailData
{
get
{
DataTable dt = new DataTable();
dt.Columns.Add("StockCode", typeof(string));
dt.Columns.Add("StockName", typeof(string));
dt.Columns.Add("SalePrice", typeof(decimal));
dt.Rows.Add(new object[] { "CS2.0", "开发框架-V2.0", 100.11 });
dt.AcceptChanges();
return dt;
}
}
private void Form1_Load(object sender, EventArgs e)
{
//绑定LookupEdit的数据源
txtStock.Properties.DisplayMember = "StockName";
txtStock.Properties.ValueMember = "StockCode";
txtStock.Properties.DataSource = StockData;
//绑定表格中LookupEdit的数据源
RepositoryItemLookUpEdit edit = gridColumn1.ColumnEdit as RepositoryItemLookUpEdit;
edit.Properties.DisplayMember = "StockName";
edit.Properties.ValueMember = "StockCode";
edit.Properties.DataSource = StockData;
//手工绑定EditValueChanged事件
edit.EditValueChanged = new EventHandler(edit_EditValueChanged);
//设置表格的数据源
gridControl1.DataSource = SaleDetailData;
}
private void edit_EditValueChanged(object sender, EventArgs e)
{
LookUpEdit edit = sender as LookUpEdit;
if (edit.EditValue != null)
{
//取资料行,数据源为DataTable, 资料行是DataRowView对象。
object o = edit.Properties.GetDataSourceRowByKeyValue(edit.EditValue);
if (o is DataRowView)
{
DataRowView rv = o as DataRowView;
gridView1.SetFocusedRowCellValue("SalePrice", rv.Row["Price"]);//取单价
}
}
else
{
labelControl4.Text = "0.00";
}
}
private void txtStock_EditValueChanged(object sender, EventArgs e)
{
if (txtStock.EditValue != null)
{
//取资料行,数据源为DataTable, 资料行是DataRowView对象。
object o = txtStock.Properties.GetDataSourceRowByKeyValue(txtStock.EditValue);
if (o is DataRowView)
{
DataRowView rv = o as DataRowView;
labelControl4.Text = rv.Row["Price"].ToString(); //取单价
}
}
else
{
labelControl4.Text = "0.00";
}
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 产品数据
/// </summary>
private DataTable StockData
{
get
{
DataTable dt = new DataTable();
dt.Columns.Add("StockCode", typeof(string));
dt.Columns.Add("StockName", typeof(string));
dt.Columns.Add("Price", typeof(decimal));
dt.Rows.Add(new object[] { "CS2.0", "开发框架-V2.0", 100.11 });
dt.Rows.Add(new object[] { "CS2.2", "开发框架-V2.2", 200.22 });
dt.Rows.Add(new object[] { "CS3.0", "开发框架-V3.0", 300.33 });
dt.AcceptChanges();
return dt;
}
}
/// <summary>
/// 销售订单明细数据
/// </summary>
private DataTable SaleDetailData
{
get
{
DataTable dt = new DataTable();
dt.Columns.Add("StockCode", typeof(string));
dt.Columns.Add("StockName", typeof(string));
dt.Columns.Add("SalePrice", typeof(decimal));
dt.Rows.Add(new object[] { "CS2.0", "开发框架-V2.0", 100.11 });
dt.AcceptChanges();
return dt;
}
}
private void Form1_Load(object sender, EventArgs e)
{
//绑定LookupEdit的数据源
txtStock.Properties.DisplayMember = "StockName";
txtStock.Properties.ValueMember = "StockCode";
txtStock.Properties.DataSource = StockData;
//绑定表格中LookupEdit的数据源
RepositoryItemLookUpEdit edit = gridColumn1.ColumnEdit as RepositoryItemLookUpEdit;
edit.Properties.DisplayMember = "StockName";
edit.Properties.ValueMember = "StockCode";
edit.Properties.DataSource = StockData;
//手工绑定EditValueChanged事件
edit.EditValueChanged = new EventHandler(edit_EditValueChanged);
//设置表格的数据源
gridControl1.DataSource = SaleDetailData;
}
private void edit_EditValueChanged(object sender, EventArgs e)
{
LookUpEdit edit = sender as LookUpEdit;
if (edit.EditValue != null)
{
//取资料行,数据源为DataTable, 资料行是DataRowView对象。
object o = edit.Properties.GetDataSourceRowByKeyValue(edit.EditValue);
if (o is DataRowView)
{
DataRowView rv = o as DataRowView;
gridView1.SetFocusedRowCellValue("SalePrice", rv.Row["Price"]);//取单价
}
}
else
{
labelControl4.Text = "0.00";
}
}
private void txtStock_EditValueChanged(object sender, EventArgs e)
{
if (txtStock.EditValue != null)
{
//取资料行,数据源为DataTable, 资料行是DataRowView对象。
object o = txtStock.Properties.GetDataSourceRowByKeyValue(txtStock.EditValue);
if (o is DataRowView)
{
DataRowView rv = o as DataRowView;
labelControl4.Text = rv.Row["Price"].ToString(); //取单价
}
}
else
{
labelControl4.Text = "0.00";
}
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
源码下载:
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网