简体   繁体   中英

Update DataGrid on run-time

I am creating Windows Application which has a Grid. 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. 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. eg if User selects 2 in the Template Field, Band2 must have two rows. As its a run time process, Grid must be refreshed on the Run time.

在此处输入图片说明

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. 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. This way the ViewModel notifies the View (or vice versa) about any changes that have been made. Thus, you can easily control the content of all 3 DataGrids.

See INotifyPropertyChanged for more on this. There are plenty of articles around who help you archiving this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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