Databinding problem

  • Thread starter Thread starter chris
  • Start date Start date
C

chris

Hi folks,

I'm getting an error when binding a combo box.. the following works
fine...

comboBox1.DataSource = m_data.Tables[0];
comboBox1.DisplayMember = "Title";
comboBox1.ValueMember = "Key";

.... but I really want the data sorted by "Title" so I tried the
following...

DataRow[] dr = m_dvdData.Tables[0].Select("","Title ASC");
comboBox1.DataSource = dr;
comboBox1.DisplayMember = "Title";
comboBox1.ValueMember = "Key";

.... but when assiging the ValueMember I get an 'Argument Exception'
error and I can't figure out why.

I also tried the select with a valid filter expression but that gave
the same result.

I also tried importing the selected datarows into a new table, but the
gave the same result.

Can anyone shed some light on this?

Cheers,

Chris.
 
Try,

m_data.Tables[0].DefaultView.Sort = "Title";
comboBox1.DataSource = m_data.Tables[0];
comboBox1.DisplayMember = "Title";
comboBox1.ValueMember = "Key";

Regards,
Phil.
 
As simple as that eh? Great stuff, thanks Phil.

Chris.

Phil Williams said:
Try,

m_data.Tables[0].DefaultView.Sort = "Title";
comboBox1.DataSource = m_data.Tables[0];
comboBox1.DisplayMember = "Title";
comboBox1.ValueMember = "Key";

Regards,
Phil.

chris said:
Hi folks,

I'm getting an error when binding a combo box.. the following works
fine...

comboBox1.DataSource = m_data.Tables[0];
comboBox1.DisplayMember = "Title";
comboBox1.ValueMember = "Key";

.... but I really want the data sorted by "Title" so I tried the
following...

DataRow[] dr = m_dvdData.Tables[0].Select("","Title ASC");
comboBox1.DataSource = dr;
comboBox1.DisplayMember = "Title";
comboBox1.ValueMember = "Key";

.... but when assiging the ValueMember I get an 'Argument Exception'
error and I can't figure out why.

I also tried the select with a valid filter expression but that gave
the same result.

I also tried importing the selected datarows into a new table, but the
gave the same result.

Can anyone shed some light on this?

Cheers,

Chris.
 
Back
Top