By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Using pulldownlist in datagridview .. can it be done!

P: n/a
Hi
I am having trouble figuring out how to use combobox in a datagridview.
What seemed to be a simple task turned out not to arrghh.

I have a dataGridView with 4 columns, one of them is column ID
(double). I want to be able to lookup a textual value using a combobox
and - when choosed - replace this textual value with the corresponding
ID ...

the pulldownlist has a dataSource pointing to a table. It shows a text
field from this table (displayMember) and inserts a double field
(valueMember)

.... when I startup the application I fill the dataAdapter. If the
adapter returns more than one row it popups with a message

System.argumentexception: datagridviewcomboboxcell value is not valid.

and I just cant find any logic in it. I assume the value in the
combobox can differ from row to row (I mean not as in the good old ms
Access days where the pulldownlist control always were the same no
matter there were many rows)

Does anyone outthere have any experience using combobox in
datagridview.

Thanks .

regards Danny

Jan 23 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

"Danny Nielsen" <da***************@ofir.dk> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Hi
I am having trouble figuring out how to use combobox in a datagridview.
What seemed to be a simple task turned out not to arrghh.

I have a dataGridView with 4 columns, one of them is column ID
(double). I want to be able to lookup a textual value using a combobox
and - when choosed - replace this textual value with the corresponding
ID ...

the pulldownlist has a dataSource pointing to a table. It shows a text
field from this table (displayMember) and inserts a double field
(valueMember)

... when I startup the application I fill the dataAdapter. If the
adapter returns more than one row it popups with a message

System.argumentexception: datagridviewcomboboxcell value is not valid.
Ussually this means that the master table has a foreign key which could not
be found in the lookup table (ValueMember field). Are you sure (1) the
lookup table is loaded and (2) contains all the keys referenced by the
master table ?

You also say you bound the DGVComboBox to a table, what do you exactly mean,
it should be bound to a second BindingSource (eg. LookupBindingSource, which
is bound to the lookup table in the DataSet on the Form) and there should
also be a second TableAdapter (eg. LookupTableAdapter) and it should be used
to fill the lookup table at Form_Load.

HTH,
Greetings


and I just cant find any logic in it. I assume the value in the
combobox can differ from row to row (I mean not as in the good old ms
Access days where the pulldownlist control always were the same no
matter there were many rows)

Does anyone outthere have any experience using combobox in
datagridview.

Thanks .

regards Danny

Jan 23 '06 #2

P: n/a
Hello HTH

The master DatagridView has a dataView lying upon a DataAdapter with
this sql source:
SELECT TVISFC818200."T$ID", TVISFC817200."T$AKTIV",
TVISFC817200."T$DESC", TVISFC818200."T$AGRP", TVISFC817200."T$TYPE"
FROM TVISFC818200 LEFT OUTER JOIN
TVISFC817200 ON TVISFC818200."T$ID" =
TVISFC817200."T$ID"

....and the comboBox has a DataSet with following Source (from a 2.
DataAdapter):
SELECT "T$AKTIV", "T$DESC", "T$ID"
FROM TVISFC817200
WHERE ("T$AKTIV" = 1)

I am using DESC and ID, with DESC as the visual text the user chooses
from and ID as the entry written in db when user selects from comboBox.
The combobox is loaded with the load of the form. I am not aware of how
to use BindingSource as I am still that new to VB - having mostly being
programming in VB.2003 (two months). Hopefully the above give you an
expression. As long as only one record is loaded with the DataGridView
no errors occur but with more the last mentioned error occur for each
row. Strange. Does this give you any hints about the reason for this ?
Thanks for any responds

Danny

Jan 24 '06 #3

P: n/a
Hi,

"Danny Nielsen" <da***************@ofir.dk> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hello HTH

The master DatagridView has a dataView lying upon a DataAdapter with
this sql source:
SELECT TVISFC818200."T$ID", TVISFC817200."T$AKTIV",
TVISFC817200."T$DESC", TVISFC818200."T$AGRP", TVISFC817200."T$TYPE"
FROM TVISFC818200 LEFT OUTER JOIN
TVISFC817200 ON TVISFC818200."T$ID" =
TVISFC817200."T$ID"
Not sure about this kind of field syntax but why are you using an outer
join, you should be using an inner join. You only want to include records
from 8182 that have a matching id in 8172, because the ComboBox is only
loaded with data from 8172. Secondly if there is a filter (WHERE) on the
lookup query then it should also be on the master query (to be safe):

SELECT TVISFC818200."T$ID", TVISFC817200."T$AKTIV",
TVISFC817200."T$DESC", TVISFC818200."T$AGRP", TVISFC817200."T$TYPE"
FROM TVISFC818200 INNER JOIN
TVISFC817200 ON TVISFC818200."T$ID" =
TVISFC817200."T$ID"
WHERE (TVISFC817200."T$AKTIV" = 1 )

...and the comboBox has a DataSet with following Source (from a 2.
DataAdapter):
SELECT "T$AKTIV", "T$DESC", "T$ID"
FROM TVISFC817200
WHERE ("T$AKTIV" = 1)

I am using DESC and ID, with DESC as the visual text the user chooses
from and ID as the entry written in db when user selects from comboBox.
The combobox is loaded with the load of the form. I am not aware of how
to use BindingSource as I am still that new to VB - having mostly being
programming in VB.2003 (two months). Hopefully the above give you an
expression. As long as only one record is loaded with the DataGridView
You didn't really say whether you have checked what i talked about in my
previous reply. Try to execute the two query somewhere, and then verify
whether the resultset from the first query does not contain id's that aren't
in the resultset for the second query.
Hope this helps,
Greetings
no errors occur but with more the last mentioned error occur for each
row. Strange. Does this give you any hints about the reason for this ?
Thanks for any responds

Danny

Jan 24 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.