473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using pulldownlist in datagridview .. can it be done!

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
3 4889
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: T.Haugnes | last post by:
I've installed visual studio c# express, .net SDK 2.0, SQL Server Express, created a table in the SQL database and filled this with some data-rows. I dragged the database-table from Data...
2
by: Bob | last post by:
How do I show a calendar control or another appropriate control to pick a date and time for a cell in a column in a datagridview? Thanks for any help. Bob
3
by: Lars E. Nes | last post by:
Hi all. I would like to automaticly select a item in a datagridview using the value of column. I do not have the index. Just the value (which is a string). How can this be done? Thanks.
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
0
by: krigare | last post by:
There maybe a better way of doing this but I am attempting to display a list of objects and their respective properties using a datagridview. The object class is straight forward with several...
7
by: BillE | last post by:
What is the best way to add data using a DataGridView in a multi-tier application (data entry is handled in a data access layer using stored procedures)? Thanks Bill
0
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I am a .NET newbie, specifically WinForms. I have a simple Winform for which I have a "How To" question: My WinForm app will display data from a FoxPro database, two tables in particular:...
6
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
1
by: Avedo | last post by:
Hello! I have a form application with a DataGridView, and an Save/Delete and Cancel button. When the application is opened, it is supplied an XML file that may or may not exist, and display the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.