472,793 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 2347
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.