WPF Delete Row from grid

自作多情 提交于 2019-12-11 03:29:40

问题


I am pretty new to WPF and am building an Charting application using WPF. I am adding new rows dynamically and it works perfectly. I am seeing a problem when removing rows. This is my code for adding rows

RowDefinition newRow = new RowDefinition();
newRow.Name = "ADX";
newRow.Height = new GridLength(1, GridUnitType.Star);
this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Add(newRow);
Grid.SetRow(scs, this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Count - 1);
this.techIndicatorToRowDefinitionMap["ADX"] = newRow;

and the code to remove the Row is

this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Remove(this.techIndicatorToRowDefinitionMap["ADX"]);

When I remove the rows , it seems like random rows are removed. Can you tell me if there is an easier way to keep track of rows and delete them or if there is a bug in this code .

Thanks.


回答1:


Hi I think your code is Removeing the RowDefinition correctly but what I think wrong is you also need to remove the children of Grid in that Row like

this.chartForm.sciChartControl.ContentGrid.Children.Remove(scs);
this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Remove(this.techIndicatorToRowDefinitionMap["ADX"]);

If you wont remove the child the RowDefinition will be removed but child will be shifted to another row .I hope this will give you an idea.



来源:https://stackoverflow.com/questions/20860193/wpf-delete-row-from-grid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!