我需要在名为ucOutputPredictionsResults
的TableLayoutPanel中显示名为predictionDictionary
的字典的内容,并在第一列中具有名称,在第二列中具有值。我的字典中所有键和值的类型均为字符串。
我可以显示键和值,但不能按我要求的顺序显示>
这是我所做的:
this.ucOutputPredictionsResults.RowCount = 0; this.ucOutputPredictionsResults.ColumnCount = 0; foreach (KeyValuePair<string, string> kvp in (_testExecution as TestExecutionAlveoGraph) .predictionDictionary) { Label lb = new Label(); lb.Text = kvp.Key; this.ucOutputPredictionsResults.Controls.Add(lb, this.ucOutputPredictionsResults.ColumnCount, this.ucOutputPredictionsResults.RowCount); Label valueLbl = new Label(); valueLbl.Text = kvp.Value; this.ucOutputPredictionsResults.Controls.Add(valueLbl, this.ucOutputPredictionsResults.ColumnCount +1, this.ucOutputPredictionsResults.RowCount); }
但是结果不是我期望的:
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9TSzRkSC5wbmcifQ==” alt =“在此处输入图像描述”>
我需要在一个名为ucOutputPredictionsResults的TableLayoutPanel中显示一个名为projectionDictionary的字典的内容,并在第一列中具有名称,在第二列中具有值...。
尽管我同意TaW的观点,即您应该显式设置TableLayoutPanel并以更受控制的方式添加控件,但是可以通过将ColumnCount设置为2并使用仅接收控件的Add()重载来解决“问题”。然后将按预期添加标签。