Could not bind to the new display member error

D

Dica

i've got a table in my dataSet that looks like this:

<tblTasks>

<taskID>0</taskID>

<projectID>0</projectID>

<summary>-- Select A Task --</summary>

</tblTasks>

<tblTasks>

<taskID>662</taskID>

<projectID>19</projectID>

<summary>Addition - Add Update to MeetComp</summary>

</tblTasks>



when trying to bind to my comboBox as follows:

cboTasks.DataSource = oDataSet.Tables["tblTasks"].Select(null, "taskID",
DataViewRowState.CurrentRows);

cboTasks.DisplayMember = "summary";

cboTasks.ValueMember = "taskID";



i get the "Could not bind ot the new display member" error. any ideas why?

tks
 
N

Nicholas Paldino [.NET/C# MVP]

Dica,

In this, you are binding to an array of data rows. I don't think that
this is a good idea.

Try creating a new DataView and binding to it, like this:

// The data view.
DataView view = new DataView(oDataSet.Tables["tblTasks"], null, "taskID",
DataViewRowState.CurrentRows);

// Set the display member before setting the data source.
cboTasks.DisplayMember = "summary";

// Set the data source to the data view.
cboTasks.DataSource = view;

Hope this helps.
 
D

Dica

Nicholas Paldino said:
Dica,

In this, you are binding to an array of data rows. I don't think that
this is a good idea.

Try creating a new DataView and binding to it, like this:

// The data view.
DataView view = new DataView(oDataSet.Tables["tblTasks"], null, "taskID",
DataViewRowState.CurrentRows);

// Set the display member before setting the data source.
cboTasks.DisplayMember = "summary";

// Set the data source to the data view.
cboTasks.DataSource = view;

works perfect. tks.

however, i'm curious, why set the display member prior to setting the
dataSource?
Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Dica said:
i've got a table in my dataSet that looks like this:

<tblTasks>

<taskID>0</taskID>

<projectID>0</projectID>

<summary>-- Select A Task --</summary>

</tblTasks>

<tblTasks>

<taskID>662</taskID>

<projectID>19</projectID>

<summary>Addition - Add Update to MeetComp</summary>

</tblTasks>



when trying to bind to my comboBox as follows:

cboTasks.DataSource = oDataSet.Tables["tblTasks"].Select(null, "taskID",
DataViewRowState.CurrentRows);

cboTasks.DisplayMember = "summary";

cboTasks.ValueMember = "taskID";



i get the "Could not bind ot the new display member" error. any ideas why?

tks
 

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