Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hi everyone,
How can i display sql image in tooltip when mouseover datagrid.I have this code that do not work.

XML
<DataGridTemplateColumn Header="Image" Width="45" >
                   <DataGridTemplateColumn.CellTemplate>
                       <DataTemplate >
                           <Border BorderBrush="Black" BorderThickness="1" CornerRadius="2" Padding="2">
                               <Image Source="{Binding Path=Picture}" Width="120" Height="50">
                                   <Image.ToolTip>
                                       <ToolTip DataContext="{Binding Path=Picture, ElementName=grdPersonnel1}" BorderBrush="LightBlue">
                                       </ToolTip>
                                   </Image.ToolTip>
                               </Image>
                           </Border>
                       </DataTemplate>
                   </DataGridTemplateColumn.CellTemplate>
Posted
Comments
Kiran Susarla 2-Jul-12 13:00pm    
Can you please elaborate more on the problem you are facing. Are you getting any error?
sahabiswarup 3-Jul-12 2:51am    
good question 5 from me.
govardhan4u 3-Jul-12 11:31am    
get the code written to display the image
[no name] 3-Jul-12 11:43am    
What is "sql image" and what does "do not work" mean?
SASS_Shooter 3-Jul-12 12:19pm    
If I understand your question then what you are asking is this:

You have an image in your program.
You want the image shown in a Tooltip.
You want that shown when you mouse over an entry in the datagrid.


You are displaying a very small snippet of what looks like XAML to me. Is this a WPF application, a Silverlight application, or just a web page?

I saved a picture in sql databse, and i can retrieve and see it in datagrid but i want to do mouse over on picture, tooltip display it more larger (zoom).
This code block has this message in tooltip:Byte[] Array.

XML
<DataGridTemplateColumn Header="Image" Width="45" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate >
                            <Image Source="{Binding Path=Picture}" Width="100" Height="50" Stretch="Uniform"  ToolTip="{Binding Path=Picture}">                           
                            </Image>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>


Add new record event:
C#
private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.* ";

                dlg.ShowDialog();

                FileStream fs = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read);
                byte[] data = new byte[fs.Length];

                fs.Read(data, 0, System.Convert.ToInt32(fs.Length));
                fs.Close();

                System.IO.Stream stream = System.IO.File.Open(dlg.FileName, System.IO.FileMode.Open);

                BitmapImage imgsrc = new BitmapImage();
                imgsrc.BeginInit();
                imgsrc.StreamSource = stream;
                imgsrc.EndInit();
                this.Picture.Source = imgsrc;

                SqlConnection con = new SqlConnection();
                con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\programing\WPF\DataBase.mdf;Integrated Security=True;User Instance=True";
                con.Open();

                SqlCommand sc = new SqlCommand("Insert Into Personnels(No,Name,Family,Picture) Values(@No,@Name,@Family,@Tozihat,@Picture)", con);

                sc.Parameters.AddWithValue("@No", txtNo.Text);
                sc.Parameters.AddWithValue("@Name", txtName.Text);
                sc.Parameters.AddWithValue("@Family", txtFamily.Text);
                sc.Parameters.AddWithValue("@Picture", data);

                sc.ExecuteNonQuery();
                con.Close();

}
 
Share this answer
 
v3
I hope this will help you.

HTML
<![CDATA[<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default6.aspx.vb" Inherits="Default6" %>]]>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900