1
Answer

Selection from datbound combo box to choose binary image in windows form

Ask a question
Ron

Ron

14y
3.5k
1

Hello, I am trying to create a windows form that a user will use a databound selection from combo box to choose an image to be displayed in a picture box or datagrid. The selection is base on categories and one selection may have multiple images associated with it.
I use a class to populate my combo box.
public
class AddValue
{
private string m_Display;
private long m_Value;
public AddValue(string Display, long Value)
{
m_Display = Display;
m_Value = Value;
}
public string Display
{
get { return m_Display; }
}
public long Value
{
get { return m_Value; }
}

and my combo box is populated in this manner
SqlConnection
roy = new SqlConnection(@"server=CAPTSISKO-PC\SQLEXPRESS;Initial Catalog=cable;Integrated Security=True");
string roySetup1 = @"Select * from GuideFeatures";
SqlCommand sqlCommand1 = new SqlCommand(roySetup1, roy);
roy.Open();
SqlDataReader rbList1 = sqlCommand1.ExecuteReader();
ArrayList setup1 = new ArrayList();
while (rbList1.Read())
{
setup1.Add(
new AddValue(rbList1.GetString(1), rbList1.GetInt32(0)));
}
rbList1.Close();
roy.Close();
comboBox1.DataSource = setup1;
comboBox1.DisplayMember =
"Display";
comboBox1.ValueMember =
"Value";
comboBox1.SelectedIndex = 4;
The problem I am running into is when I try to  pull the information from the combox box selection into datagrid is
The mult-part identifier "PicForm.Form1" could not be bound. Invalid column name AddValue.
Here is my code for the datagrid
string
instrPic = comboBox1.SelectedItem.ToString();
SqlConnection roy1 = new SqlConnection(@"server=CAPTSISKO-PC\SQLEXPRESS;Initial Catalog=cable;Integrated Security=True");
roy1.Open();
string newPic = "Select Pic from guidePic WHERE picTitle = " + instrPic + "";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(newPic, roy1);
da.Fill(ds,
"newPic");
dataGridView1.DataSource = ds;
dataGridView1.DataMember =
"newPic";
roy1.Close();

when I look at the process in debug mode the combobox.selecteditem.tostring() has the selection in it but it displays {picform.form1.AddValue}, is there a way i can pull the display answer out of this, it is there I just don't know how to get it to display instead of the AddValue.
Oh is it easier to put the image in a picture box instead of datagrid also, not sure how to do that
Thanks

Answers (1)