简体   繁体   English

在运行时更新DataGrid

[英]Update DataGrid on run-time

I am creating Windows Application which has a Grid. 我正在创建具有网格的Windows应用程序。 Grid's data source is a an Object of a Class. 网格的数据源是类的对象。 Grid has two bands. 网格有两个波段。 As shown in the below image on Band1, there is a Column named as Templates. 如下图所示,在Band1上有一个名为Templates的列。 It has values from 1 to 10. The requirement is that based on the selected values in the Template Field, Band2 must have no of rows. 它具有从1到10的值。要求是,根据模板字段中的选定值,波段2必须没有行。 eg if User selects 2 in the Template Field, Band2 must have two rows. 例如,如果用户在“模板”字段中选择2,则Band2必须有两行。 As its a run time process, Grid must be refreshed on the Run time. 作为其运行时过程,必须在运行时刷新Grid。

在此处输入图片说明

In the below case if the value is changed from 2 to 3 in the template field, the open Band2 must be refreshed to show 3 rows. 在以下情况下,如果在模板字段中将值从2更改为3,则必须刷新打开的Band2以显示3行。 I wrote some code but it was not able to refresh the grid on the run time. 我编写了一些代码,但无法在运行时刷新网格。

 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();
            }

What am I missing here? 我在这里想念什么?

You could implement the interface INotifyPropertyChanged and some additional properties you may notify of. 您可以实现INotifyPropertyChanged接口和一些可能通知的其他属性。 This way the ViewModel notifies the View (or vice versa) about any changes that have been made. 这样,ViewModel会通知View(反之亦然)有关所做的任何更改。 Thus, you can easily control the content of all 3 DataGrids. 因此,您可以轻松控制所有3个DataGrid的内容。

See INotifyPropertyChanged for more on this. 有关更多信息,请参见INotifyPropertyChanged There are plenty of articles around who help you archiving this. 周围有很多文章可以帮助您存档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM