Unable to cast object of type System.Data.DataRowView to type System.IConvertible  

Posted in

Wow...


Long time.. A lot of distractions. I have been interested in a lot new things. With Windows Phone, Robotics coming into picture, the hobbies and pass-times all changed around.

But to get back on the track.. Here is a very small piece of information that I am sure would help a lot of people.

I encountered the above error while working with a Combobox in a Windows Application.

This would come up every time the form loads and the the SelectedValue of the combobox was selected.

This normally would occur to comboboxes, which are databound.

So here is the problem and the solution.

This is how we usually bind the combobox to data

cboBox.DataSource = data_set.Tables["table_name"].DefaultView;

cboBox.DisplayMember = "field_name";

cboBox.ValueMember = "field_id";


Instead, to resolve this issue all we need to do is first specify the DisplayMember and ValueMember and then Bind.


cboBox.DisplayMember = "field_name";

cboBox.ValueMember = "field_id";

cboBox.DataSource = data_set.Tables["table_name"].DefaultView;


This entry was posted on Tuesday, October 19, 2010 at Tuesday, October 19, 2010 and is filed under . You can follow any responses to this entry through the comments feed .

2 comments

Anonymous  

Thank u very much

10:27
Anonymous  

thank u soooo ver much man!!!!
but y does this happen!?

15:39

Post a Comment