Click here to Skip to main content
12,953,349 members (47,607 online)
Rate this:
 
Please Sign up or sign in to 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 26-Jan-13 2:34am

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,930


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 26 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100