-2

I'm trying to populate rows in my data grid and I'm getting a 1061 error. How do I fix this. Second, how can I set the number of empty rows?

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>

Produces a CS1061 error

1 Answers1

0

The compiler tells you that Datagrid does not have Rows (it has Items)

See this answer if you want to add them manually.

And my advice: it would be better to bind to a List (ObservableCollection). See this answer

less
  • 699
  • 6
  • 25