473,796 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2 combo boxes in datagrid

Hi Al

I want to add two combobox columns in my datagrid. the one combobox column must be bound to the same datasource that the datagrid is, and the other combobox I just want to populate with a whole lot of values, and then when the user selects a value, I want it to filter the possible values in the other combobox. Is this possible? Also this unbound combobox that hold the whole lot of values, I want to insert it next to the combobox that will be filtered

I have a typed dataset with all the relevant tables, I have a Data access layer that exposes this typed dataset and has methods that populats the datatables in the typed dataset.

My Datagrid is bound to a datatable called Jobcards. Now I want a combobox column(the unbound one) to have a list of all the possible customers, and when the user selects the customer I want the second combobox(which is bound) to be filtered to only the possible contact people for that specific customer and it must store that specific customer contact ID. I have got two tables in a database. One is called Customers, and the other CustomerContact s and the two have a relationship based on the customerID

What I want to know after this whole long explanation is, Can I do this, and if so how? Datagrids are quite new to me, so I am anticipating alot of reading! Please can somebody point me in the right direction, and/or provide me with and explantion of how to do this. I have managed to insert 1 combobox column and bind it to a datasource but I'm having difficulty adding that column inbetween other columns! So I suppose this is a start, but I don't know how to add the unbound column to my datagrid and do all that filtering stuff

Please help... I aplogise if my english is bad..

TI
Kevin
Nov 15 '05 #1
3 2417
sorry but I forgot to mention that this is a windows datagrid not an ASP one, and I'm using win XP with VS 200
thank
Kevin
Nov 15 '05 #2
Here's some code on MSDN (I Didn't write it) for creating a
DataGridComboBo xColumn and DataGridComboBo x. Since the DataGridComboBo x
inherits ComboBox, you can still bind it and if you create two different
columns, you can add values to one statically and bind the other, bind them
to the same source, whatever you please:

#Region "DataGridComboB ox"
Public Class DataGridComboBo x
Inherits ComboBox
Private WM_KEYUP As Integer = &H101
Protected Overrides Sub WndProc(ByRef m As System.Windows. Forms.Message)
If m.Msg = WM_KEYUP Then
Return
End If
MyBase.WndProc( m)
End Sub
End Class
#End Region

#Region "DataGridComboB oxColumn"
Public Class DataGridComboBo xColumn
Inherits DataGridTextBox Column
Public myCombo As DataGridComboBo x
Private m_isEditing As Boolean
Public Sub New()
MyBase.New()
myCombo = New DataGridComboBo x
AddHandler myCombo.Leave, New EventHandler(Ad dressOf LeaveComboBox)
AddHandler myCombo.Selecti onChangeCommitt ed, New
EventHandler(Ad dressOf OnSelectionChan geCommitted)
End Sub
Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager ,
ByVal Rownum As Integer, _
ByVal bounds As Rectangle, ByVal readOnly1 As Boolean, ByVal
instantText As String, ByVal _
cellIsVisible As Boolean)
MyBase.Edit(sou rce, Rownum, bounds, readOnly1, instantText,
cellIsVisible)
myCombo.Parent = Me.TextBox.Pare nt
myCombo.Locatio n = Me.TextBox.Loca tion
myCombo.Size = New Size(Me.TextBox .Size.Width, myCombo.Size.He ight)
myCombo.Text = Me.TextBox.Text
Me.TextBox.Visi ble = False
myCombo.Visible = True
myCombo.BringTo Front()
myCombo.Focus()
End Sub
Private Sub LeaveComboBox(B yVal sender As Object, ByVal e As EventArgs)
myCombo.Hide()
End Sub
Protected Overloads Overrides Function Commit(ByVal dataSource As
CurrencyManager , ByVal rowNum As Integer) As Boolean
If m_isEditing Then
m_isEditing = False
SetColumnValueA tRow(dataSource , rowNum, myCombo.Text)
End If
Return True
End Function
Private Sub OnSelectionChan geCommitted(ByV al sender As Object, ByVal e As
EventArgs)
m_isEditing = True
MyBase.ColumnSt artedEditing(CT ype(sender, Windows.Forms.C ontrol))
End Sub
End Class
#End Region

Then, here's an example of adding it to the the TableStyle:

Dim csExcelJob As New DataGridTextBox Column
Debug.Assert(Al lData.Tbl_Job_T racking.Columns (11).ColumnName =
"Excel_Job_numb er")
With csExcelJob
.MappingName = AllData.Tbl_Job _Tracking.Colum ns(11).ColumnNa me
.HeaderText = "Facilty Job#"
.Width = 85
.NullText = ng
End With
tsMain.GridColu mnStyles.Add(cs ExcelJob)
'Delete Code Column
Dim csDeleteCode As New DataGridComboBo xColumn
With csDeleteCode
.MappingName = AllData.Tbl_Job _Tracking.Colum ns(12).ColumnNa me
.HeaderText = "Delete Code"
.Width = 85
.NullText = ng
End With
With csDeleteCode.my Combo.Items
.Add("DS")
.Add("ND")
.Add("BA")
.Add("CB")
.Add("CW")
.Add("ID")
.Add("MD")
End With
csDeleteCode.my Combo.DropDownS tyle = ComboBoxStyle.D ropDownList

tsMain.GridColu mnStyles.Add(cs DeleteCode)
dg.TableStyles. Add(tsMain)
"Kevin" <an*******@disc ussions.microso ft.com> wrote in message
news:92******** *************** ***********@mic rosoft.com...
Hi All

I want to add two combobox columns in my datagrid. the one combobox column must be bound to the same datasource that the datagrid is, and the other
combobox I just want to populate with a whole lot of values, and then when
the user selects a value, I want it to filter the possible values in the
other combobox. Is this possible? Also this unbound combobox that hold the
whole lot of values, I want to insert it next to the combobox that will be
filtered.
I have a typed dataset with all the relevant tables, I have a Data access layer that exposes this typed dataset and has methods that populats the
datatables in the typed dataset.
My Datagrid is bound to a datatable called Jobcards. Now I want a combobox column(the unbound one) to have a list of all the possible customers, and
when the user selects the customer I want the second combobox(which is
bound) to be filtered to only the possible contact people for that specific
customer and it must store that specific customer contact ID. I have got two
tables in a database. One is called Customers, and the other
CustomerContact s and the two have a relationship based on the customerID.
What I want to know after this whole long explanation is, Can I do this, and if so how? Datagrids are quite new to me, so I am anticipating alot of
reading! Please can somebody point me in the right direction, and/or provide
me with and explantion of how to do this. I have managed to insert 1
combobox column and bind it to a datasource but I'm having difficulty adding
that column inbetween other columns! So I suppose this is a start, but I
don't know how to add the unbound column to my datagrid and do all that
filtering stuff?
Please help... I aplogise if my english is bad...

TIA
Kevin

Nov 15 '05 #3
Hi Willia

Thanks for the reply, I guess I'll have to try to convert this to C#. Anyway, I was thinking, how do I keep the two comboboxes in sync with each other, because obvoiously each row is going to have a different combination of CustID vs custDetailsID. So how do I keep these two comboboxes in sync while still keeping the CustDetaisID in sync with the typed dataset's datatable.

TI
Kevin
Nov 15 '05 #4

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

Similar topics

4
1541
by: Steve Chatham | last post by:
I have a page where I have some combo boxes on it. A click on each one spawns another box, and another until each area has been selected, or until they choose to pull all items into a datagrid from that category. For instance: say the first combo has in it: meat dairy
6
258
by: Sebastian Santacrice | last post by:
I have a few combo boxes that are multi lines and each row of data corresponds with the other combo boxed rows of data. But then they there a lot of rows one combo box scrolls down and the other stay the same. So now the rows of data don't match from one combo box to the others. Is there some way to make the others boxes scroll with one so the rows always match. Basically I want it to work like a datagrid regarding the scrolling....
6
3768
by: Ron L | last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying to display in a datagrid. This datasource has 4 columns that I am interested in here, a text column and 3 value columns corresponding to permissions to certain data classes. I want to put the permission values in combo boxes in the grid and instead of displaying the numeric values, have the combo box display a string that corresponds to the numeric value (i.e. No...
3
4279
by: Frustrated Developer via DotNetMonster.com | last post by:
I have posted a couple times on here already and found the user community to be very helpful. I took on a project before I realized how difficult a time I'm having working with a database. Assistance would be greatly appreciated! I am trying to allow certain users to be able to preview a database's contents without being able to update which I've accomplished. I've created a "Preview" button and set the datagrid to READ ONLY. Now I want...
0
1041
by: Ausclad | last post by:
Hi all, I have a datagrid, which is bound to a datatable. In the datagrid, I have changed some of the fields to be combo boxes. In the datagrid I want to be able to allow the user to change the value of a cell, based on a combo box selection. For example, in a timesheet data entry, we want to enter what type of leave the person may have had. eg, sick leave, annual leave etc.
2
1629
by: Ausclad | last post by:
How Would you implement this? I have an existing Access application that needs to be converted to .net I am restricted to use the existing database design. One of the areas is a timesheet data entry screen. The existing Access app writes to a table (tblTimesheetHours). In the data entry screen, the fields, like employee name, job, etc are bound to combo
7
1852
by: Ausclad | last post by:
Ok, ill try again..... It seems fairly simple. I have two combo boxes in a datagrid. The datagrid is bound to a a table in a dataset. The two combo boxes are bound to a single data table in a different dataset. One combo box is displaying the Employees payroll ID. The other is
6
3684
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
1
2909
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a main form (RD Form) with 4 combo boxes (i.e. cbo1, cbo2, etc) and a subdatasheet (the subform...let's call it subInfo) below the combo boxes on the RD Form. I hope this eliminates any confusion of the
0
1257
by: bz | last post by:
Hi, I have a datagrid with two columns Region and City Both have combo-boxes. City column is unbound What I want is, when use select a region, to fill the combo for City column with appropriate cities for that region I did this with a code like this private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
0
9673
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
9525
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
10221
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
10169
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
10003
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
9050
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
7546
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
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.