wpf 填充数据网格行时发生CS1061错误[重复]

7qhs6swi  于 2023-03-24  发布在  其他
关注(0)|答案(1)|浏览(111)

此问题在此处已有答案

Manually add rows in WPF DataGrid(2个答案)
11小时前关门了。
我试图填充数据网格中的行,但出现了1061错误。如何修复此错误。第二,如何设置空行的数量?
C#

string[] row1 = new string[] { "a", "", "Form 1" };
            string[] row2 = new string[] { "b", "", "Form 2" };
            string[] row3 = new string[] { "S ", "", "Form 3" };
            string[] row4 = new string[] { "d ", "", "Form 4" };
            string[] row5 = new string[] { "e ", "", "Form 5" };
            string[] row6 = new string[] { "f ", "", "Form 6" };
            object[] rows = new object[] { row1, row2, row3, row4, row5, row6 };

            foreach (string[] rowArray in rows)
            {
                election_grid.Rows.Add(rowArray);
            }

XAML语言

<DataGrid x:Name="election_grid" Grid.Column ="1" Grid.Row="30" Grid.ColumnSpan="6" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Election" Width="150"/>
                    <DataGridCheckBoxColumn Header="Default?" Width="150"/>
                    <DataGridTextColumn Header="Other Election" Width="150"/>
                    <DataGridTextColumn Header="Election Effective Date" Width="150"/>
                    <DataGridTextColumn Header="Date Election must be filed" Width="200"/>
                </DataGrid.Columns>
            </DataGrid>

生成CS1061错误

x4shl7ld

x4shl7ld1#

编译器告诉您Datagrid没有行(它有项)
如果您想手动添加它们,请参阅此answer
我的建议是最好绑定到List(ObservableCollection)。参见this answer

相关问题