System.Data.DataRowView in combobox

  • Thread starter Thread starter William
  • Start date Start date
W

William

I have attached a column to a combobox, but I only get
System.Data.DataRowView in the combobox's item list. I double checked to
be sure that the table name and the column names are spelled correctly.
any suggestions?

My code:
daSelectResource.Fill( dsResourceGroup );
cboSelectResource.DataSource = dsResourceGroup.Tables[0];
cboSelectResource.DisplayMember = "ResourceDetails";

I am retrieving the value with:
string wholeRecord = cboSelectResource.SelectedItem.ToString();

// I have also tried cboSelectResource.Text;


any suggestions as to why:
1) System.Data.DataRowView is displayed as the entries in the combobox
2) wholeRecord has value System.Data.DataRowView?

Thanks.
 
William,

That happens to me when I have misspelled the column name being assigned to
the DisplayMember property. I've found that both the spelling and the case
must match the column name.

Kerry Moorman
 
William,
I agree with Kerry's answer to question #1.
As to your question #2, the SelectedItem is returning the entire DataRowView
and the ".ToString()" will take its default value and return it as a string.
The default value of a DaraRowView is a string stating its datatype, which is
what you are getting. Try treating the object cboSelectResource.SelectedItem
as a DataRowView and you should be able to get what you want.

-Dave

Kerry Moorman said:
William,

That happens to me when I have misspelled the column name being assigned to
the DisplayMember property. I've found that both the spelling and the case
must match the column name.

Kerry Moorman


William said:
I have attached a column to a combobox, but I only get
System.Data.DataRowView in the combobox's item list. I double checked to
be sure that the table name and the column names are spelled correctly.
any suggestions?

My code:
daSelectResource.Fill( dsResourceGroup );
cboSelectResource.DataSource = dsResourceGroup.Tables[0];
cboSelectResource.DisplayMember = "ResourceDetails";

I am retrieving the value with:
string wholeRecord = cboSelectResource.SelectedItem.ToString();

// I have also tried cboSelectResource.Text;


any suggestions as to why:
1) System.Data.DataRowView is displayed as the entries in the combobox
2) wholeRecord has value System.Data.DataRowView?

Thanks.
 
William,

Can it be that your select statement is wrong,

Just a gues, because you are using C# don't I think that you mix up uper and
lowercases.

Cor
 
Kerry,

I have doubled check my spelling and my case, and both my spelling
and case are both correct.
Any other suggestions for what causes the combobox to display
System.Data.DataRowView?

William

William,

That happens to me when I have misspelled the column name being assigned to
the DisplayMember property. I've found that both the spelling and the case
must match the column name.

Kerry Moorman


William said:
I have attached a column to a combobox, but I only get
System.Data.DataRowView in the combobox's item list. I double checked to
be sure that the table name and the column names are spelled correctly.
any suggestions?

My code:
daSelectResource.Fill( dsResourceGroup );
cboSelectResource.DataSource = dsResourceGroup.Tables[0];
cboSelectResource.DisplayMember = "ResourceDetails";

I am retrieving the value with:
string wholeRecord = cboSelectResource.SelectedItem.ToString();

// I have also tried cboSelectResource.Text;


any suggestions as to why:
1) System.Data.DataRowView is displayed as the entries in the combobox
2) wholeRecord has value System.Data.DataRowView?

Thanks.
 
"Try treating the object cboSelectResource.SelectedItem
as a DataRowView and you should be able to get what you want."
I am not too sure what you mean. Can you please give a code fragment?

I need to retrieve the text value as it appears in the combobox.

William

William,
I agree with Kerry's answer to question #1.
As to your question #2, the SelectedItem is returning the entire DataRowView
and the ".ToString()" will take its default value and return it as a string.
The default value of a DaraRowView is a string stating its datatype, which is
what you are getting. Try treating the object cboSelectResource.SelectedItem
as a DataRowView and you should be able to get what you want.

-Dave

Kerry Moorman said:
William,

That happens to me when I have misspelled the column name being assigned to
the DisplayMember property. I've found that both the spelling and the case
must match the column name.

Kerry Moorman


William said:
I have attached a column to a combobox, but I only get
System.Data.DataRowView in the combobox's item list. I double checked to
be sure that the table name and the column names are spelled correctly.
any suggestions?

My code:
daSelectResource.Fill( dsResourceGroup );
cboSelectResource.DataSource = dsResourceGroup.Tables[0];
cboSelectResource.DisplayMember = "ResourceDetails";

I am retrieving the value with:
string wholeRecord = cboSelectResource.SelectedItem.ToString();

// I have also tried cboSelectResource.Text;


any suggestions as to why:
1) System.Data.DataRowView is displayed as the entries in the combobox
2) wholeRecord has value System.Data.DataRowView?

Thanks.
 
My select stmt:
SELECT [Resource ID], ResourceDetails FROM qryResourceCombined

I am trying to attach ResourceDetails to the combobox.

The column name and case matches the schema identically.

William
 
William,
If what you want is the value from the column of the selected row, an easier
way might be to set :
cboSelectResource.ValueMember = "ResourceDetails";
then when you want to retrieve it:

string wholeRecord = cboSelectResource.SelectedValue

However, for this to work, you'll have to get the first problem resolved.

On the first problem, have you tried setting the DataSource to
dsResourceGroup.TableName instead of instead of dsResourceGroup.Tables[0]?
Substitute the actual name of the Table for TableName.

Can we assume that the column ResourceDetails is defined as a string and
that the Dataset dsResourceGroup has only the one Table in it?

Let me know if this works,
Dave


William said:
"Try treating the object cboSelectResource.SelectedItem
as a DataRowView and you should be able to get what you want."
I am not too sure what you mean. Can you please give a code fragment?

I need to retrieve the text value as it appears in the combobox.

William

William,
I agree with Kerry's answer to question #1.
As to your question #2, the SelectedItem is returning the entire DataRowView
and the ".ToString()" will take its default value and return it as a string.
The default value of a DaraRowView is a string stating its datatype, which is
what you are getting. Try treating the object cboSelectResource.SelectedItem
as a DataRowView and you should be able to get what you want.

-Dave

Kerry Moorman said:
William,

That happens to me when I have misspelled the column name being assigned to
the DisplayMember property. I've found that both the spelling and the case
must match the column name.

Kerry Moorman


:

I have attached a column to a combobox, but I only get
System.Data.DataRowView in the combobox's item list. I double checked to
be sure that the table name and the column names are spelled correctly.
any suggestions?

My code:
daSelectResource.Fill( dsResourceGroup );
cboSelectResource.DataSource = dsResourceGroup.Tables[0];
cboSelectResource.DisplayMember = "ResourceDetails";

I am retrieving the value with:
string wholeRecord = cboSelectResource.SelectedItem.ToString();

// I have also tried cboSelectResource.Text;


any suggestions as to why:
1) System.Data.DataRowView is displayed as the entries in the combobox
2) wholeRecord has value System.Data.DataRowView?

Thanks.
 
William,

Can you try it, just to see what is the problem with

SELECT * FROM qryResourceCombined

I hope this helps,

Cor
 
William,
Have you resolved this issue yet?

I failed to give a code fragment to explain using the selecteditem as a
datarowview.
Here it is:

string wholeRecord = cboSelectResource.SelectedItem["ResourceDetails"];

Dave

William said:
"Try treating the object cboSelectResource.SelectedItem
as a DataRowView and you should be able to get what you want."
I am not too sure what you mean. Can you please give a code fragment?

I need to retrieve the text value as it appears in the combobox.

William

William,
I agree with Kerry's answer to question #1.
As to your question #2, the SelectedItem is returning the entire DataRowView
and the ".ToString()" will take its default value and return it as a string.
The default value of a DaraRowView is a string stating its datatype, which is
what you are getting. Try treating the object cboSelectResource.SelectedItem
as a DataRowView and you should be able to get what you want.

-Dave

Kerry Moorman said:
William,

That happens to me when I have misspelled the column name being assigned to
the DisplayMember property. I've found that both the spelling and the case
must match the column name.

Kerry Moorman


:

I have attached a column to a combobox, but I only get
System.Data.DataRowView in the combobox's item list. I double checked to
be sure that the table name and the column names are spelled correctly.
any suggestions?

My code:
daSelectResource.Fill( dsResourceGroup );
cboSelectResource.DataSource = dsResourceGroup.Tables[0];
cboSelectResource.DisplayMember = "ResourceDetails";

I am retrieving the value with:
string wholeRecord = cboSelectResource.SelectedItem.ToString();

// I have also tried cboSelectResource.Text;


any suggestions as to why:
1) System.Data.DataRowView is displayed as the entries in the combobox
2) wholeRecord has value System.Data.DataRowView?

Thanks.
 
I have exactly the same problem. I have no idea what the cause could be.

Any help is greatly appreciated.
 
cboSelectResource.DataSource = dsResourceGroup;
cboSelectResource.DisplayMember = "qryResourceCombined.ResourceDetails";

should do the trick with filling the combobox.

As to retrieving values from the ComboBox:
string strResource
=((DataRowView)this.cboSelectResource.SelectedItem)["ResourceDetails"].T
oString();
 
Back
Top