Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I have been Bind the Image and other record in the Listview but i have problem in binding the record in DataGrid using linq to sql Please tell me how to bind the Image and first name in the DataGrid . I try to bind it but finally the result in my student table is null means no error but it show no record i am sure that i have some binding problem how can i solve it please please tell me and Thanks for reading . Here is My .xaml file of wpf please see and correct the errors on this fill
<Window x:Class="UI.ViewStudent"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:UI"Title="ViewStudent" Height="577" Width="415" xmlns:my="clr-      namespace:Microsoft.Windows.Controls;assembly=WPFToolkit">
        <Window.Resources >
            <local:ImageDataConverter x:Key="ImageData1Converter"/>
        </Window.Resources>
        <Grid Height="540">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="9*" />
                <ColumnDefinition Width="384*" />
            </Grid.ColumnDefinitions>
            <my:DataGrid ItemsSource="{Binding }" AutoGenerateColumns="False" Grid.Column="1" Margin="32,0,53,0" Name="dataGrid1" Height="200" VerticalAlignment="Top">
                <my:DataGrid.Columns>
                    <my:DataGridTemplateColumn Header="FirstName">
                        <my:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                             <TextBox Text="{Binding Path=FirstName}" 
                                             Margin="-6,0,-6,0"/>
                            </DataTemplate>
                        </my:DataGridTemplateColumn.CellTemplate>
                    </my:DataGridTemplateColumn>
 
                    <my:DataGridTemplateColumn Header="Imagess">
                        <my:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Image Height="100" Source="{Binding Path=MyImage, Converter={StaticResource ImageData1Converter}}" />
                            </DataTemplate>
                        </my:DataGridTemplateColumn.CellTemplate>
                    </my:DataGridTemplateColumn>
                </my:DataGrid.Columns>
            </my:DataGrid>
        </Grid >
    </Window>

 
I also try like this
     
<Grid Height="540">
            <Grid.ColumnDefinitions>
 
                <ColumnDefinition Width="9*" />
 
                <ColumnDefinition Width="115*" />
 
                <ColumnDefinition Width="269*" />
 
            </Grid.ColumnDefinitions>
 
            <my:DataGrid ItemsSource="{Binding }" AutoGenerateColumns="False" Grid.Column="1" Margin="32,0,53,0" Name="dataGrid1" Height="200" VerticalAlignment="Top" Grid.ColumnSpan="2">
                <my:DataGrid.Columns>
                    <my:DataGridTextColumn Binding="{Binding FirstName}" Header="First Name"/>
                </my:DataGrid.Columns>
                <ItemsControl Name="imageItems">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                           <Image Height="100" Source="{Binding Path=MyImage, Converter={StaticResource ImageData1Converter}}" />

OR i do like that Path=
    <Image Height="100" Source="{Binding Path= MyImage, Converter={StaticResource ImageData1Converter}}" /> 
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </my:DataGrid>
        </Grid >
    </Window>
But error is for Path=
<Image Height="100" Source="{Binding Path= MyImage, Converter={StaticResource ImageData1Converter}}" />
that is Having no solution by doing this error is that Error
1 The Element type 'System.Windows.DataTemplate' does not have an associated TypeConverter to parse the string '
Path='. Line 26 Position 35.
C:\Documents and Settings\Muhammad Yaqoob\My Documents\Visual Studio 2008\Projects\BLL\UI\ViewStudent.xaml
And my .xaml.cs file is
namespace UI
    {
        public partial class Pics : Window
        {
            public Pics()
            {
                InitializeComponent();
            }
            private DataClasses1DataContext db = new DataClasses1DataContext();
 
            private BindingListCollectionView CustomerView;
 
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                var custsInCA = from c in db.Students
                                where c.StudentID  == 100
                                orderby c.LastName, c.FirstName
                                select c;
 
                this.DataContext = custsInCA;
                this.CustomerView = ((BindingListCollectionView)(CollectionViewSource.GetDefaultView(this.DataContext)));
            }
        }
 
        public class ImageDataConverter : IValueConverter
        {
 
             public object Convert(object value, Type targetType, object parameter,
 
             System.Globalization.CultureInfo culture)
             {
                System.Data.Linq.Binary binaryData = value as System.Data.Linq.Binary;
                //System.Data.Linq.Binary binaryData = value;// here there is the first error .How convert BinaryData to Object??
                if (binaryData == null)
                {
                    return null;
                }
                byte[] buffer = binaryData.ToArray();
                if (buffer.Length == 0)
                {
                    return null;
                }
 
                BitmapImage res = new BitmapImage();
                res.BeginInit();
                res.StreamSource = new System.IO.MemoryStream(buffer);
                res.EndInit();
                return res;
            }
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                    throw new NotImplementedException();
            }
        }
    }
In Short i want to Bind the Image by converting it from VarBinary to image which i converted in by using i value converter And the FirstName, LastName so on in the DataGrid using linq to sql wpf C# please if some one is expert for fixing the error or of some one know complete process of Binding the image and other record using linq to sql so please for good sack help me i am waiting for response of the noble and the good person please. your few minutes can solve my problem
Posted 11-Jan-12 9:01am
Edited 11-Jan-12 9:11am
(no name)10.1K
v2

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
Web03 | 2.8.141220.1 | Last Updated 11 Jan 2012
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