1
votes

Hey gus i have button:

 GetData();
            dataGrid1.ItemsSource = DriverCollection.ToList();

When i click it datagrid does not filling only adding two rows (my collection contains two rows) which is empty and very narrow

this is my class

 private class DriverData 
        {
            public string DriverName { get; set; }
            public decimal DriverSalary { get; set; }
        }

collection :

private ObservableCollection<DriverData> _DriverCollection = new ObservableCollection<DriverData>();

private ObservableCollection<DriverData> DriverCollection 
        {
            get { return _DriverCollection; }
        }

GetData method << its works correctly collection is filling with two rows:

for (int i = 0; i < FilteredDriverNamesList.Count; i++)
            {
                _DriverCollection.Add(new DriverData { DriverName = FilteredDriverNamesList[i], DriverSalary = _DriverSalarys[i] });
            }

and the grid:

 <sdk:DataGrid AutoGenerateColumns="False" Name="dataGrid1" FontSize="14" Margin="12,0,0,0"
                      HorizontalAlignment="Left" Width="549" Height="273" VerticalAlignment="Top" ItemsSource="{Binding DriverCollection}">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding DriverName}" Width="200"/>
                <sdk:DataGridTextColumn Binding="{Binding DriverSalary}" Width="140"/>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>

Edit: I have solved the problem i edited private with public on my class Thanks

1

1 Answers

1
votes

Ok, this is great job you have done so far,

Can you change DriverCollection and make it public. i.e

 public ObservableCollection<DriverData> DriverCollection 
    {
        get { return _DriverCollection; }
    }