Neelam Prajapati
Neelam Prajapati

Reputation: 3802

DataGrid doesn't show data from list

I am trying to bind static data list to DataGrid in WPF. But it doesn't bind data. Here it is what I have tried so far

but data is not displayed in the DataGrid.

xaml code

<DataGrid Height="148" HorizontalAlignment="Left" Margin="12,22,0,0" 
           Name="dataGrid1" VerticalAlignment="Top" Width="693" >
    <DataGrid.Columns>
        <DataGridTextColumn Header="LICENSE TYPE"/>
        <DataGridTextColumn Header="CV VERSION" />
        <DataGridTextColumn Header="IP TOTAL" />
        <DataGridTextColumn Header="IP ALLOCATED" />
        <DataGridTextColumn Header="ANALOG TOTAL" />
        <DataGridTextColumn Header="ANALOG ALLOCATED" />
        <DataGridTextColumn Header="UPDATE AVAILBLE" />
    </DataGrid.Columns>
</DataGrid>

xaml.cs code

public LicenseServer()
{
    InitializeComponent();
    dataGrid1.ItemsSource = LoadCollectionData();
    dataGrid1.AutoGenerateColumns = false;
}

private List<clsLicense> LoadCollectionData()
{
    List<clsLicense> license = new List<clsLicense>();
    license.Add(new clsLicense()
    {
        LICENSE_TYPE ="CV Pro",     
        CV_VERSION= "4.6",
        IP_PORTAL ="100",       
        IP_ALLOCATED="50",     
        ANALOG_TOTAL="200",     
        ANALOG_ALLOTED="50",   
        UPDATE_AVAILABLE ="N/A"            
    });

    license.Add(new clsLicense()
    {
        LICENSE_TYPE = "CV Pro",
        CV_VERSION = "4.6",
        IP_PORTAL = "100",
        IP_ALLOCATED = "50",
        ANALOG_TOTAL = "200",
        ANALOG_ALLOTED = "50",
        UPDATE_AVAILABLE = "N/A"
    });

    return license;
}

what I am doing wrong?

Upvotes: 0

Views: 124

Answers (1)

ASh
ASh

Reputation: 35646

you didn't provide bindings for columns. this code

<DataGridTextColumn Header="LICENSE TYPE"/>

declares a column with a header only.

you should set Binding property. Make sure that LICENSE_TYPE, etc are properties of a view model item, not fields

<DataGridTextColumn Header="LICENSE TYPE" Binding="{Binding Path=LICENSE_TYPE}"/>

Upvotes: 2

Related Questions