Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF
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 3:34am

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

  Print Answers RSS
0 Kornfeld Eliyahu Peter 275
1 Maciej Los 204
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 183
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 26 Jan 2013
Copyright © CodeProject, 1999-2014
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