combo box populated but selectedItem returning system.Data.DataRowView

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
 
J

Jerry

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
 
G

Guest

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
 
M

Mr. Arnold

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top