Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Combo Box Again

0 views
Skip to first unread message

Devron Blatchford

unread,
Oct 14, 2002, 7:14:27 PM10/14/02
to
Hi there,

I am having trouble getting arround the combo box binding to a datatable.

Assuming I bind using the following method:
combo.Datasource = datatable
combo.DisplayMember = "NameField"
combo.ValueMember = "IDField"

I have a couple of questions:

1) If I put code in the combo_SelectedIndexChange it seems to fire for each
item in the combo when the combo is loading. While this is happening the
SelectedValue returns a "DataRowView" object as its type when I assume it
should be "Integer" after loading the SelectedValue does return "Integer" as
it's type.

2) If the combo box is sorted via the sorted property then the DisplayMember
sorts but the value member does not. This means that the SelectedValue does
not return the ID of the selected Item but the ID of the field if the combo
was not sorted. Is this a bug?

3) As I am binding to a datatable how can I get a reference to the selected
DataRow and why does the SelectedItem have a type of DataRowView and not
DataRow? I actually need to access several accosiated fields in the DataRow
when an item is selected.

Can someone please explain these?

Thanks
Devron


.net datagridcolumnstyles

unread,
Oct 15, 2002, 7:03:07 AM10/15/02
to
Hi Devron,
1. This seems to be a common complaint with the combobox. One way to get
round this is to add the handler after you bind the data. So instead of
letting VS automatically create a handler for you, you should do it yourself
(see AddHandler for VB.net)

2. It's not a bug directly. The documents say that an exception will be
raised if you attempt to sort a combobox that is bound to a data source,
however if you set the Sorted property to True before you bind then the
exception is not raised (not raising the exception is probably the bug here)
and the display and value members don't match anymore. Try moving the
Sorted=True line to after you bind and you will see the exception. You
should do your sorting in the data source.

3. DataRowView has a Row property that will give you the DataRow and you can
then access the columns.

Hope that helps you a little
J.

Jasmine
www.datagridcolumnstyles.net
Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid

"Devron Blatchford" <dev...@auspine.com.au> wrote in message
news:#ZyARc9cCHA.1300@tkmsftngp08...

Devron Blatchford

unread,
Oct 15, 2002, 7:16:45 PM10/15/02
to
Thanks very much, that clears it up.

".net datagridcolumnstyles" <sup...@datagridcolumnstyles.net> wrote in
message news:u4RYrpDdCHA.3752@tkmsftngp08...

0 new messages