簡體   English   中英

在運行時更新DataGrid

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM