[英]Update DataGrid on run-time
我正在创建具有网格的Windows应用程序。 网格的数据源是类的对象。 网格有两个波段。 如下图所示,在Band1上有一个名为Templates的列。 它具有从1到10的值。要求是,根据模板字段中的选定值,波段2必须没有行。 例如,如果用户在“模板”字段中选择2,则Band2必须有两行。 作为其运行时过程,必须在运行时刷新Grid。
在以下情况下,如果在模板字段中将值从2更改为3,则必须刷新打开的Band2以显示3行。 我编写了一些代码,但无法在运行时刷新网格。
private void grdDataMapping_AfterCellUpdate(object sender, CellEventArgs e)
{
if (e.Cell.Column.Key.Equals("TemplateName"))
{
ValueList paramName = new ValueList();
string templateName = e.Cell.Text;
List<TemplateMapping> tempMappings = new List<TemplateMapping>();
if (_dictTemplateNames.ContainsKey(templateName))
{
for (int i = 0; i < templateName.Value; i++)
tempMappings.Add(new TemplateMapping());
mappingDetails.ListTemplateMapping = tempMappings;
}
grdDataMapping.Refresh();
}
我在这里想念什么?
您可以实现INotifyPropertyChanged
接口和一些可能通知的其他属性。 这样,ViewModel会通知View(反之亦然)有关所做的任何更改。 因此,您可以轻松控制所有3个DataGrid的内容。
有关更多信息,请参见INotifyPropertyChanged 。 周围有很多文章可以帮助您存档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.