Click here to Skip to main content
14,696,481 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi,I retrieve data from database with LINQ technology and store it in res:
var db = new DCDataContext();
           var res= from t in db.staffs
                    select new {t.lName , t.fName ,t.pic};

staff is my table in database and I want to display lName ,fName and pic in a datagrid.
when I bind res to datagrid,it displays just fName and lName and not pic. for resolve this problem
I define a List<> and add staffs in it:
List<stf> ls=new List<stf>();
         stf s = new stf();
         foreach(var a in res)
         {


              s.lName = a.lName;
              s.fName = a.fName;
              s.img = (((System.Data.Linq.Binary)a.pic).ToArray());
              ls.Add(s);
         }


         dataGrid1.ItemsSource = ls;

stf is a class with properties like field of staff
but when I run it ,datagrid shows empty rows
when I debug it with breakpoint Itemsource is fill and has true data but datagrid
displays nothing!!!!!
my xaml cod:
<Window.Resources>
        <local:ImageConverter x:Key="ConvertImage"></local:ImageConverter>
    </Window.Resources>
    <Grid>
        
        
        <DataGrid Height="200" HorizontalAlignment="Left" Margin="44,47,0,0" 

                  Name="dataGrid1" VerticalAlignment="Top" Width="407" 

                  AutoGenerateColumns="False" FlowDirection="RightToLeft">
            <DataGrid.Columns>
                
                <DataGridTemplateColumn  Header="picture" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ContentControl Content="{Binding img,Converter={StaticResource ConvertImage}}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                
                <DataGridTextColumn  Binding="{Binding fName}" Header="Name" />
                <DataGridTextColumn  Binding="{Binding lName}" Header=" Family" />
               
            </DataGrid.Columns>
        </DataGrid>

please advance me to bind a List to dataGrid correctly
Posted
Updated 1-Sep-20 2:10am

1 solution

lName, fName, etc should be public properties of stf .
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900