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