Click here to Skip to main content
11,805,035 members (63,464 online)

mermaid-I asked:

Open original thread
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());

         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:
        <local:ImageConverter x:Key="ConvertImage"></local:ImageConverter>
        <DataGrid Height="200" HorizontalAlignment="Left" Margin="44,47,0,0" 
                  Name="dataGrid1" VerticalAlignment="Top" Width="407" 
                  AutoGenerateColumns="False" FlowDirection="RightToLeft">
                <DataGridTemplateColumn  Header="picture" IsReadOnly="True">
                            <ContentControl Content="{Binding img,Converter={StaticResource ConvertImage}}" />
                <DataGridTextColumn  Binding="{Binding fName}" Header="Name" />
                <DataGridTextColumn  Binding="{Binding lName}" Header=" Family" />
please advance me to bind a List to dataGrid correctly
Tags: WPF


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2015
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