473,465 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Create 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 CustomerContacts 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 2395
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
DataGridComboBoxColumn and DataGridComboBox. Since the DataGridComboBox
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 "DataGridComboBox"
Public Class DataGridComboBox
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 "DataGridComboBoxColumn"
Public Class DataGridComboBoxColumn
Inherits DataGridTextBoxColumn
Public myCombo As DataGridComboBox
Private m_isEditing As Boolean
Public Sub New()
MyBase.New()
myCombo = New DataGridComboBox
AddHandler myCombo.Leave, New EventHandler(AddressOf LeaveComboBox)
AddHandler myCombo.SelectionChangeCommitted, New
EventHandler(AddressOf OnSelectionChangeCommitted)
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(source, Rownum, bounds, readOnly1, instantText,
cellIsVisible)
myCombo.Parent = Me.TextBox.Parent
myCombo.Location = Me.TextBox.Location
myCombo.Size = New Size(Me.TextBox.Size.Width, myCombo.Size.Height)
myCombo.Text = Me.TextBox.Text
Me.TextBox.Visible = False
myCombo.Visible = True
myCombo.BringToFront()
myCombo.Focus()
End Sub
Private Sub LeaveComboBox(ByVal 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
SetColumnValueAtRow(dataSource, rowNum, myCombo.Text)
End If
Return True
End Function
Private Sub OnSelectionChangeCommitted(ByVal sender As Object, ByVal e As
EventArgs)
m_isEditing = True
MyBase.ColumnStartedEditing(CType(sender, Windows.Forms.Control))
End Sub
End Class
#End Region

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

Dim csExcelJob As New DataGridTextBoxColumn
Debug.Assert(AllData.Tbl_Job_Tracking.Columns(11). ColumnName =
"Excel_Job_number")
With csExcelJob
.MappingName = AllData.Tbl_Job_Tracking.Columns(11).ColumnName
.HeaderText = "Facilty Job#"
.Width = 85
.NullText = ng
End With
tsMain.GridColumnStyles.Add(csExcelJob)
'Delete Code Column
Dim csDeleteCode As New DataGridComboBoxColumn
With csDeleteCode
.MappingName = AllData.Tbl_Job_Tracking.Columns(12).ColumnName
.HeaderText = "Delete Code"
.Width = 85
.NullText = ng
End With
With csDeleteCode.myCombo.Items
.Add("DS")
.Add("ND")
.Add("BA")
.Add("CB")
.Add("CW")
.Add("ID")
.Add("MD")
End With
csDeleteCode.myCombo.DropDownStyle = ComboBoxStyle.DropDownList

tsMain.GridColumnStyles.Add(csDeleteCode)
dg.TableStyles.Add(tsMain)
"Kevin" <an*******@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.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
CustomerContacts 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
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...
6
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...
6
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...
3
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....
0
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...
2
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...
7
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...
6
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
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...
0
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
1
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...
0
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...
0
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...
0
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 ...

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.