473,608 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView and ComboBox columns

I am trying to populate a DataGridView Combobox column with a different data
binding source (dataset) depending upon a selection made in a previous
column. I can handle the previous column but how do I assign the following
properties dynamically in code?

DataPropertyNam e
DataSource
DisplayMember

I do see how to set these at design time but that won't do because I need
different data in the combobox per each row depending upon the previous
selection made.
I hope I explained the problem well enough.

Mar 12 '07 #1
4 6034
VJ
In the Value Changed Event of previous column, you can set the properties as
below

if ( value.Equals("1 ") )
{
cb1.DataSource = dsTables.Tables["Table1"];
cb1.DisplayMemb er="Col1";
}
else
{
cb1.DataSource = dsTables.Tables["Table2"];
cb1.DisplayMemb er="Col2";
}
"Chris" <Ch***@discussi ons.microsoft.c omwrote in message
news:6F******** *************** ***********@mic rosoft.com...
>I am trying to populate a DataGridView Combobox column with a different
data
binding source (dataset) depending upon a selection made in a previous
column. I can handle the previous column but how do I assign the following
properties dynamically in code?

DataPropertyNam e
DataSource
DisplayMember

I do see how to set these at design time but that won't do because I need
different data in the combobox per each row depending upon the previous
selection made.
I hope I explained the problem well enough.

Mar 12 '07 #2
I am trying to do a similar sort of thing (but I populate the second combo
box from a list, not a data source) and I have found an even bigger problem.
If I select "option one" in the first column and then fill the second
column's combo box with options "1, 2, 3, 4", I have no problems. For this
example, I pick item 3 for column two. However, if I start a second row and
select "option two" in the first column and then try and fill the combo box
in column two with "5, 6, 7, 8", then I get a data error because "3", the
selection made in row one, is no longer a valid selection for the combo box
in column two. Even if you resolve the problem you are having, then you will
still be restricted by this problem.

Hopefully, someone can help us resolve this as well.

Phil

"Chris" wrote:
I am trying to populate a DataGridView Combobox column with a different data
binding source (dataset) depending upon a selection made in a previous
column. I can handle the previous column but how do I assign the following
properties dynamically in code?

DataPropertyNam e
DataSource
DisplayMember

I do see how to set these at design time but that won't do because I need
different data in the combobox per each row depending upon the previous
selection made.
I hope I explained the problem well enough.
Mar 12 '07 #3
VJ
Phil, you have to clear the DataSet binding, and the ComboxText before
associating a new DataSource. At the minimum, you should say ComboxBox1.Text
= "" and then bind the new datasource. If you have any code in the second
combobox selectedIndex or ValueChanged, beware of them, they might fire when
you clear text.. depending on how your property is organized..

VJ

"Phil" <Ph**@discussio ns.microsoft.co mwrote in message
news:F2******** *************** ***********@mic rosoft.com...
>I am trying to do a similar sort of thing (but I populate the second combo
box from a list, not a data source) and I have found an even bigger
problem.
If I select "option one" in the first column and then fill the second
column's combo box with options "1, 2, 3, 4", I have no problems. For
this
example, I pick item 3 for column two. However, if I start a second row
and
select "option two" in the first column and then try and fill the combo
box
in column two with "5, 6, 7, 8", then I get a data error because "3", the
selection made in row one, is no longer a valid selection for the combo
box
in column two. Even if you resolve the problem you are having, then you
will
still be restricted by this problem.

Hopefully, someone can help us resolve this as well.

Phil

"Chris" wrote:
>I am trying to populate a DataGridView Combobox column with a different
data
binding source (dataset) depending upon a selection made in a previous
column. I can handle the previous column but how do I assign the
following
properties dynamically in code?

DataPropertyNa me
DataSource
DisplayMembe r

I do see how to set these at design time but that won't do because I need
different data in the combobox per each row depending upon the previous
selection made.
I hope I explained the problem well enough.

Mar 12 '07 #4
I think this will work for a stand-alone combobox but not for a combobox used
within the atagridview.

I am instead going to add another column and depedning upon the first
selection, either column A or Column B will be active.
"VJ" wrote:
Phil, you have to clear the DataSet binding, and the ComboxText before
associating a new DataSource. At the minimum, you should say ComboxBox1.Text
= "" and then bind the new datasource. If you have any code in the second
combobox selectedIndex or ValueChanged, beware of them, they might fire when
you clear text.. depending on how your property is organized..

VJ

"Phil" <Ph**@discussio ns.microsoft.co mwrote in message
news:F2******** *************** ***********@mic rosoft.com...
I am trying to do a similar sort of thing (but I populate the second combo
box from a list, not a data source) and I have found an even bigger
problem.
If I select "option one" in the first column and then fill the second
column's combo box with options "1, 2, 3, 4", I have no problems. For
this
example, I pick item 3 for column two. However, if I start a second row
and
select "option two" in the first column and then try and fill the combo
box
in column two with "5, 6, 7, 8", then I get a data error because "3", the
selection made in row one, is no longer a valid selection for the combo
box
in column two. Even if you resolve the problem you are having, then you
will
still be restricted by this problem.

Hopefully, someone can help us resolve this as well.

Phil

"Chris" wrote:
I am trying to populate a DataGridView Combobox column with a different
data
binding source (dataset) depending upon a selection made in a previous
column. I can handle the previous column but how do I assign the
following
properties dynamically in code?

DataPropertyNam e
DataSource
DisplayMember

I do see how to set these at design time but that won't do because I need
different data in the combobox per each row depending upon the previous
selection made.
I hope I explained the problem well enough.


Mar 13 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1253
by: Bob | last post by:
How is it possible to have 2 or more columns of data with headers showing in the dropdownlist of the combox in a datagridview? Using Vs2005 and VB.Net. Can't seem to find any doc on this. I know that custom controls can do this like the C1 controls but I'm trying to stay away from them as much as possible. Any help would be appreciated, Bob
2
16334
by: Nathan | last post by:
Hi, I have a datagridview bound to a List of objects (ObjectA). Each ObjectA contains an ObjectB property. Class ObjectA { public ObjectB objB {} }
8
34257
by: George | last post by:
Hi, I have been trying to see if I can do the following: 1. Create a DataGridView 2. Create 2 columns in the DataGridView (1 textbox and the other combobox) 3. Create a DataTable containing my data. (AutoGenerateColumns is true). The data is 2 columns of System.String cell. 4. If I assign the DataTable to DataGridView.DataSource, I get 4 columns. 2
1
1174
by: fiaolle | last post by:
Hi I have a DataGrid with ComboBox columns. I want the same thing to happen as when a user clicks and chooses an item in the ComboBox. When a user stands in the last row (new row) and clicks for choosing an item and it's in the list, a new row appears beneath. I want the same thing to happen when a user types in what he wants, as what you can do in Access ComboBoxes, and when he leaves the ComboBox a new row appears. Is there a way to...
3
94240
by: sklett | last post by:
I'm changing from a DataGrid to a DataGridView and have run across a problem. The items that are bound to the DataGrid have an int Property that represents a primary key of a lookup table in my database. For example: table JobTypes 1 | Manager 2 | Controller 3 | Supervisor table Employee
0
1124
by: BiT | last post by:
Hello i'm using the datagridview control in vb.net. one of the column is combobox i worte this code to enter value to the combobox Dim _messageId As New DataGridViewComboBoxCell _messageId.Items.Add("foo") _messageId.Items.Add("bar")
0
1705
by: Dom | last post by:
I have a datagridview control, and one column is a ComboboxColumn. I simply create a ComboboxColumn, add items to it, then add the column to the Datagridview control. If I were working with a simple ComboBox, I could capture an event that fired everytime the selected item changed. Is that possible if the DatagridView control? I've looked at various events, but none give me what I want. For example, the CellEndEdit event won't fire...
0
1686
by: priyamtheone | last post by:
There's an editable datagridview populated from a table say tblItems. Among the columns of the datagridview there's a combobox column named 'Category'. This column is populated by the respective 'Category' column of tblItems. Now in the 'Category' column of the datagridview I want to set the value of a certain cell to Null programmatically. Suppose when I press keyboard Delete button over the cell or some other button on the form, the value of...
0
2845
by: visweswaran2830 | last post by:
Hi, I am having datagridview in that I have datagridview combobox column and noraml textfield. I want to know that how can I load selected value in that combox box when I am loading all entered details in data grid view.
0
8063
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8478
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8152
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8341
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6817
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1331
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.