C# – items collection must be empty before using itemssource – datagrid wpf

cdatagridwpf

I keep getting this error when trying to explicitely define the datagrid columns. If I comment out the 3 datagridtext columns, it works (but I want to hide some columns obviously). In my code, all I am doing is setting the datacontext for DataGridLookupsTab..not messing with itemsource or anything in my code. Any idea what I might be doing wrong here ?

Thanks !

<TabItem Header="Lookups" Height="23" VerticalAlignment="Top">
            <Grid x:Name="DataGridLookupsTab" Background="#FFE5E5E5" Margin="0,0,-1,-2" DataContext="Apps.OMS.Models.Lookups">
                <ComboBox x:Name="ComboBoxDistinctLookups" HorizontalAlignment="Left" Margin="128,14,0,0" VerticalAlignment="Top" Width="228" ItemsSource="{Binding Path=LookupTypeList}" SelectionChanged="ComboBoxDistinctLookups_SelectionChanged"/>
                <Label Content="Select Lookup Type" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" RenderTransformOrigin="1.105,4.731"/>
                <DataGrid x:Name="DataGridLookups" HorizontalAlignment="Left" Margin="10,41,0,0" VerticalAlignment="Top" Width="768" Height="327" ItemsSource="{Binding LookupRecords}" > 
                    <DataGridTextColumn Binding="{Binding LookupType}" Header="Lookup Type" />
                    <DataGridTextColumn Binding="{Binding LookupValue}" Header="Lookup Value" />
                    <DataGridTextColumn Binding="{Binding LookupDescription}" Header="Lookup Description" />
                </DataGrid>
            </Grid>
        </TabItem>

Best Answer

Actually the problem ended up being my lack of the Datagrid.Columns tag. Thanks

Related Topic