Filling DataRow[] into combobox

K

kimtherkelsen

Hi,
I do this:

this.comboBox.DataSource =
myDataSet.Tables["receivers"].Select("location_key = " +
selectedLocationKey);
this.comboBox.DisplayMember = "text";
this.comboBox.ValueMember = "subcustomer_location_key";

but get an exception when setting the value member. Unfortunately there
is something wrong with my debugger so I can't see what is in the
exception. I am sure that the columns are named "text" and
"subcustomer_location_key".
I have also tried with the table name: "subreceivers.text" and
"subreceivers.subcustomer_location_key". The same thing happens.

How do I refer to the columns of the data rows in the DataRow array so
that the combobox understands it?

Best regards,
Kim
 
D

Dave Sexton

Hi Kim,

Try loading the data into a new DataView class and use the RowFilter
property instead. You can bind to the DataView directly.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

What is wrong with your debugger?
the code seems to be ok but if you do not know what is going on is a little
difficult to know the reason.

Also a little more detail could help, what exception u r getting and where?
 
D

Dave Sexton

Hi Kim,

I shouldn't have wrote "loading the data" since the DataView doesn't contain
any data at all, it just wraps the specified DataTable. In other words, you
should just create a "view" of the data that you want - using a DataView
won't actually copy the data into a new object.

DataView view = myDataSet.Tables["receivers"].DefaultView;
or
DataView view = new DataView(myDataSet.Tables["receivers"]);

view.RowFilter = "location_key=" + selectedLocationKey;

comboBox.DataSource = view;
comboBox.DisplayMember = "text";
comboBox.ValueMember = "subcustomer_location_key";

Also, you should think about strong-typing your DataSet.

--
Dave Sexton

Dave Sexton said:
Hi Kim,

Try loading the data into a new DataView class and use the RowFilter
property instead. You can bind to the DataView directly.

--
Dave Sexton

Hi,
I do this:

this.comboBox.DataSource =
myDataSet.Tables["receivers"].Select("location_key = " +
selectedLocationKey);
this.comboBox.DisplayMember = "text";
this.comboBox.ValueMember = "subcustomer_location_key";

but get an exception when setting the value member. Unfortunately there
is something wrong with my debugger so I can't see what is in the
exception. I am sure that the columns are named "text" and
"subcustomer_location_key".
I have also tried with the table name: "subreceivers.text" and
"subreceivers.subcustomer_location_key". The same thing happens.

How do I refer to the columns of the data rows in the DataRow array so
that the combobox understands it?

Best regards,
Kim
 
K

kimtherkelsen

Hi Dave!

Thank you for your help - it works. I had forgotten that the DataView
existed :)

Best regards,
Kim Therkelsen

Hi Kim,

I shouldn't have wrote "loading the data" since the DataView doesn't contain
any data at all, it just wraps the specified DataTable. In other words, you
should just create a "view" of the data that you want - using a DataView
won't actually copy the data into a new object.

DataView view = myDataSet.Tables["receivers"].DefaultView;
or
DataView view = new DataView(myDataSet.Tables["receivers"]);

view.RowFilter = "location_key=" + selectedLocationKey;

comboBox.DataSource = view;
comboBox.DisplayMember = "text";
comboBox.ValueMember = "subcustomer_location_key";

Also, you should think about strong-typing your DataSet.

--
Dave Sexton

Dave Sexton said:
Hi Kim,

Try loading the data into a new DataView class and use the RowFilter
property instead. You can bind to the DataView directly.

--
Dave Sexton

Hi,
I do this:

this.comboBox.DataSource =
myDataSet.Tables["receivers"].Select("location_key = " +
selectedLocationKey);
this.comboBox.DisplayMember = "text";
this.comboBox.ValueMember = "subcustomer_location_key";

but get an exception when setting the value member. Unfortunately there
is something wrong with my debugger so I can't see what is in the
exception. I am sure that the columns are named "text" and
"subcustomer_location_key".
I have also tried with the table name: "subreceivers.text" and
"subreceivers.subcustomer_location_key". The same thing happens.

How do I refer to the columns of the data rows in the DataRow array so
that the combobox understands it?

Best regards,
Kim
 
K

kimtherkelsen

Hi Ignacio,
I think I have to rephrase the problem with the debugger.

I am developing software for a Windows CE 4.2 PDA. When I run the
software on the PDA from Visual Studio 2005 in debug mode and get an
exception, the contents of the exception can not be shown because some
sort of debugging information is missing.

To make the software made in VS2005 run on the PDA I had to install the
..Net compact framework 2.0 manually. I think somehow the missing debug
information is related to the installation of the .Net framework.

Best regards,
Kim

Hi,

What is wrong with your debugger?
the code seems to be ok but if you do not know what is going on is a little
difficult to know the reason.

Also a little more detail could help, what exception u r getting and where?


--
Ignacio Machin
machin AT laceupsolutions com

Hi,
I do this:

this.comboBox.DataSource =
myDataSet.Tables["receivers"].Select("location_key = " +
selectedLocationKey);
this.comboBox.DisplayMember = "text";
this.comboBox.ValueMember = "subcustomer_location_key";

but get an exception when setting the value member. Unfortunately there
is something wrong with my debugger so I can't see what is in the
exception. I am sure that the columns are named "text" and
"subcustomer_location_key".
I have also tried with the table name: "subreceivers.text" and
"subreceivers.subcustomer_location_key". The same thing happens.

How do I refer to the columns of the data rows in the DataRow array so
that the combobox understands it?

Best regards,
Kim
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Hi Ignacio,
I think I have to rephrase the problem with the debugger.

I am developing software for a Windows CE 4.2 PDA. When I run the
software on the PDA from Visual Studio 2005 in debug mode and get an
exception, the contents of the exception can not be shown because some
sort of debugging information is missing.

Weird, are you getting something about "resource assembly" ?
To make the software made in VS2005 run on the PDA I had to install the
.Net compact framework 2.0 manually. I think somehow the missing debug
information is related to the installation of the .Net framework.

I had never need to install the framework manually, it's always installed
from the IDE when you run the app.

I think you have something wrong with your dev. environment.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

This seems like the old "resource assembly" error in 1.1, maybe is the same
one.

Check the blog of the CF to see if there are answers there.


--
Ignacio Machin
machin AT laceupsolutions com

Hi again,

I get the message:
"An error message cannot be displayed because an optional resource
assembly containing it cannot be found"
whenever I get an exception.

It IS necessary to install the .Net framework 2.0 manually:
http://blogs.msdn.com/markprenticems/archive/2006/08/08/692624.aspx

Best regards,
Kim

Ignacio Machin ( .NET/ C# MVP ) skrev:
 

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