Using pulldownlist in datagridview .. can it be done!

D

Danny Nielsen

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
 
B

Bart Mermuys

Hi,

Danny Nielsen said:
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
 
D

Danny Nielsen

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
 
B

Bart Mermuys

Hi,

Danny Nielsen said:
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
 

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