combo box populated but selectedItem returning system.Data.DataRowView

  • Thread starter Thread starter Jerry
  • Start date Start date
J

Jerry

Hi

I have a combo box that is populated by an ole db connection to a ms access
table (Valuewave). The column that is used in the table is called waves.

The combo box is populated with the correct values, but when I refer to the
selectedItem value using WaveItem = cboWaves.SelectedItem.ToString();
MessageBox.Show(WaveItem);
I get System.Data.DataRowView. I have checked the spelling of the database
in the connection string, the table, and the column and they are correct.
How can I resolve this?

Doug
 
Sorry I should have copied my code:

OleDbCommand strCommand = new OleDbCommand(strSelect, myConnection);

OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(strCommand);

myConnection.Open();

DataSet DS = new DataSet();

myDataAdapter.Fill(DS);

cboWaves.DataSource = DS.Tables[0];

cboWaves.DisplayMember = "Valuewave";

cboWaves.ValueMember = "waves";

WaveItem = ((DataRowView)cboWaves.SelectedItem)["waves"].ToString();



I am changed the assignment of waveItem from my first post.



Doug
 
Jerry,
the Items in a databound ComboBox actually *are* DataRowViews. This short
code snippet may help:

DataRowView recRowView = cboName.SelectedItem;
DataRow recName = recRowView.Row;
lblAccountNum.Text = recName.AccountNum;
lblCompanyName.Text = recName.CompanyName;
--Peter
 
Jerry said:
Sorry I should have copied my code:

OleDbCommand strCommand = new OleDbCommand(strSelect, myConnection);

OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(strCommand);

myConnection.Open();

DataSet DS = new DataSet();

myDataAdapter.Fill(DS);

cboWaves.DataSource = DS.Tables[0];

cboWaves.DisplayMember = "Valuewave";

cboWaves.ValueMember = "waves";

WaveItem = ((DataRowView)cboWaves.SelectedItem)["waves"].ToString();



I am changed the assignment of waveItem from my first post.

That cbobox is being loaded from the DS.Tables[0] like it's view/object
collection.

The simplest way to deal with this is you're going to have to walk/read the
record set and do cboWaves.additem (record set field), until you reach the
end of the record set.
 
Back
Top