473,698 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linking combobox columns in data grid VB.net

2 New Member
That quotation was add b4 i need to know from VB.Net wizards The answer
"I'm trying to use a datagrid for data entry. I've created a couple of combo
box columns using information from
http://64.78.52.104/FAQ/WinForms/FAQ_c44c.asp#q4 80q

That example basically sets every combobox in a given column (for every row)
to the same datasource.
One obstacle I have to overcome is when a user changes a value in one
column, the next combobox in the next column on the same row needs to bind to
a new set of data, and only for that row. For example, Column A is Cost
Centers, Column B is Job Codes. If I select a Cost Center from Column A, the
combo in Column B needs to list only valid Job Codes for the previously
selected Cost Center, on a row-by-row basis.

Any idea how to do this, or is there a sample somewhere someone could point
me to?
Thanks
May 7 '07 #1
1 9014
alexmax2003
2 New Member
18. How do I have a combo box column display a sub set of data based upon the value of a different combo box column?
Sometimes data that you want to display in the DataGridView has a relationship between two tables such as a category and subcategory. You want to let the user select the category and then choose between a subcategory based upon the category. This is possible with the DataGridView by using two combo box columns. To enable this, two versions of the filtered list (subcategory) needs to be created. One list has no filter applied while the other one will be filtered only when the user is editing a subcategory cell. Two lists are required due to the requirement described in 3.5.1 section that a combo box cells value must be in the items collection or else a DataError event is raised. In this case, since all combo box cells in the column use the same datasource if you filter the datasource for one row then a combo box cell in another row might not have its value visible in the datasource, thus causing a DataError event.

The below example uses the Northwind database to display related data from the Territory and Region tables (a territory is in a specific region.) Using the category and subcategory concept, the Region is the category and the Territory is the subcategory.

private void Form1_Load(obje ct sender, EventArgs e)
{
this.territorie sTableAdapter.F ill(this.northw indDataSet.Terr itories);
this.regionTabl eAdapter.Fill(t his.northwindDa taSet.Region);

// Setup BindingSource for filtered view.
filteredTerrito riesBS = new BindingSource() ;
DataView dv = new DataView(northw indDataSet.Tabl es["Territorie s"]);
filteredTerrito riesBS.DataSour ce = dv;

}

private void dataGridView1_C ellBeginEdit(ob ject sender,
DataGridViewCel lCancelEventArg s e)
{
if (e.ColumnIndex == territoryComboB oxColumn.Index)
{
// Set the combobox cell datasource to the filtered BindingSource
DataGridViewCom boBoxCell dgcb = (DataGridViewCo mboBoxCell)data GridView1
[e.ColumnIndex, e.RowIndex];
dgcb.DataSource = filteredTerrito riesBS;

// Filter the BindingSource based upon the region selected
this.filteredTe rritoriesBS.Fil ter = "RegionID = " +
this.dataGridVi ew1[e.ColumnIndex - 1, e.RowIndex].Value.ToString ();
}
}

private void dataGridView1_C ellEndEdit(obje ct sender, DataGridViewCel lEventArgs e)
{
if (e.ColumnIndex == this.territoryC omboBoxColumn.I ndex)
{
// Reset combobox cell to the unfiltered BindingSource
DataGridViewCom boBoxCell dgcb = (DataGridViewCo mboBoxCell)data GridView1
[e.ColumnIndex, e.RowIndex];
dgcb.DataSource = territoriesBind ingSource; //unfiltered

this.filteredTe rritoriesBS.Rem oveFilter();
}
}
May 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1718
by: JAdrianB | last post by:
I'm trying to use a datagrid for data entry. I've created a couple of combo box columns using information from http://64.78.52.104/FAQ/WinForms/FAQ_c44c.asp#q480q That example basically sets every combobox in a given column (for every row) to the same datasource. One obstacle I have to overcome is when a user changes a value in one column, the next combobox in the next column on the same row needs to bind to a new set of data, and...
0
3269
by: Jesper Denmark | last post by:
Well I'm new to C# and I do not know of all of the different controls yet. The grid you are referring to is that the datagrid control, and if yes, would it be possible to use it without a database for storing my data. I have my data stored in collections. Do you know of any good tutorials on the (data)grid control that could show me how to implement something like the property tables in VS.NET where you have this multicolumn grid and are...
2
1630
by: Michael Schindler | last post by:
why see my combobox not in datagrid with values(offen, closed) not to column the 5? Please help me! This is my first combobox and i have no idea what i can to do. My source:
1
2494
by: anonymous | last post by:
I've been trying to put a them, please help me out. Here's the major parts of my code: public Form1() { DataSet myDataSet = new DataSet("myDataSet"); DataTable testTable = new DataTable("table"); testTable.Columns.Add("Col1", typeof(Int32)); testTable.Columns.Add("Col2", typeof(String)); testTable.Rows.Add(testTable.NewRow());
2
4019
by: dimension | last post by:
Hi, i have one question and one opinion i seek. please assist if you can. I am using VS2005 beta. 1) I have two tables with the following columns Security: security_id, name, symbol, exchange_id Exchange: exchange_id, symbol, name 2) I have a Form that contains a combobox (cb1) and DataViewGrid (dg1). 3) The source for the DataViewGrid is the Security table and the source of the combo box is the Exchange table 4) Before assigning the...
4
3078
by: Randy | last post by:
Hello, I've got a Form which has a dataGrid on it. In one of the columns of the dataGrid, I've implemented a ComboBox using a DataGridComboBoxColumn Class. I've also over ridden the other columns with a custom DataGridTextBoxColumn class so I can color certain columns. What I'm trying to do is.based on the selection in the ComboBox, I want to color certain cells.
1
1177
by: Irfan | last post by:
hi, All I am trying to achieve a simple programming task ie; when the user selects an item from the comboBox ,the relevant data should be displayed in the grid. I am using Publisher & Titles tables of Biblo.mdb as an example, where in Publisher names are displayed in the cmbox and all the titles related to each are disaplyed in the grid.This is what i am doing but nothing is displayed in the grid . Can someone advise pl. 'fill the...
2
1889
by: Simon Verona | last post by:
I have a combobox that is contained within a user control. Whilst the application is running, I'm attaching the combobox to a new dataset. The problem I'm getting is that the combobox doesn't appear to reflect the new dataset. The same code seems to work fine if the combobox is set to the dataset on initialisation. What have I done wrong? The code in full that I'm using to update the dataset and attach to the combobox is as follows...
2
3682
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a different item no in it..then, these records will be saved in a temporary datatable (which i made in a separate class, the name is WBASKET)...The item nos of these records will be displayed in a combobox, say item1, item2, etc.. then,i have a datagrid...
0
8680
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
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9030
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...
0
8871
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...
1
6528
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
5861
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
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.