1. I have designed the Listbox styles and data templates where I plan to show the images.
The part of a datatemplate code:
>
Tjhe parf of the ListBox Code:
ItemTemplate="{StaticResource GroupDataTemplate}"
ItemsSource="{Binding Tables[0]}"
IsSynchronizedWithCurrentItem="True"
Name="GroupListBox"
Style="{StaticResource PhotoListBoxStyle}"
Margin="10"
SelectionMode="Extended"
SelectedIndex="0"
MouseDoubleClick="GroupListBox_MouseDClick">
The Code behing in .cs file:
DataSet dtSet = new DataSet();
using (connection = new SqlConnection(connectionString))
{
command = new SqlCommand(sql, connection);
SqlDataAdapter adapter = new SqlDataAdapter();
connection.Open();
adapter.SelectCommand = command;
adapter.Fill(dtSet, "Product_Group");
GroupListBox.DataContext = dtSet;
}
First of all, I could not get the picture displayed the picture in the database. Second of all, How can I trap the Primary key the selected ListBoxItem so that I can show the next Window with the details of the Selected ListBox Item.
What I have done here but does not work is:
private void GroupListBox_MouseDClick(object sender, MouseButtonEventArgs e)
{
using (connection = new SqlConnection(connectionString))
{
connection.Open();
DataSet ds = new DataSet();
ListBoxItem lb = (GroupListBox.SelectedItem as ListBoxItem);
SqlDataAdapter sqa = new SqlDataAdapter("Select Code from Product_Group where name='" + lb.Content + "'", connection);
sqa.Fill(ds);
connection.Close();
this.Close();
}
}
I'd be grateful if I could any help. Thanking you in advance. :)
Mamta MPosted Dec 28, 2010, 4:34 AM
1) The picture needs to be stored with data type "image" in the database
2) The code needs some tweaking as follows
DataRowView drw = (DataRowView)GroupListBox.SelectedValue;
string name = drw.Row[1].ToString();
using (connection = new SqlConnection(connectionString))
{
connection.Open();
DataSet ds = new DataSet();
SqlDataAdapter sqa = new SqlDataAdapter("Select Code from Product_Group where name='" + name + "'", connection);
Make the changes as above. Then it works perfectly fine.