468,315 Members | 1,351 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

Combo Boxes in Datagrids

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
displaying the Employees name.

The users are entering timesheet hours for employees. They want to be able
to select the employee by either payroll id, or employee name.

If they select a payroll id from the first combo box, I need the second
combo box to display the matching employee surname.

I cannot see anyway to do this.

I can only seem to get the selected index of the combo box being selected.
(by using the editing control event and casting the datagrid comboboxcolumn
to a combo box). However, I dont know how I can set the selected index of
the other combo box.

Can anyone help? (besides telling me to buy some third party control!)

thankyou

Oct 9 '06 #1
7 1645
Hi there,

Sounds like you've had problems getting help.
I'll try as best I can but need you to provide some more info first.

1. Windows or web application? .NET 1.1 I presume?
2. Post some code; specifically where you do your binding/fill the
combos.

If you can get a reference to the actual combobox in question, then it
should not be too hard to select the right item. But assigning the
right information to the combobox in the first place is the important
part. For example, in windows app, you can iterate through the items
collection and check each item's bound row for a match to the ID
selected in the other cbx.

Steven

Oct 9 '06 #2
Im using version 2.0

This is a windows form.

I am using the standard DatagridView. This is bound to a dataset generated
by the dataset designer.

I have gone into the designer for the DataGridView and changed the
properties of the two columns previously mentioned to combo boxes (instead of
text boxes).

On the form load, I create a dataset and use stored procedures to populate
various tables with lookup data.

I then bind the combo boxes in the datagrid to these dataset tables

eg
with DataGridCombo1
.DisplayMember = "EmpCode"
.ValueMember = "Surname"
.DataSource = dsLookups.Tables("EmplsCodeLookup")
end with

now...teh comboboxes that are embedded in the datagrid do not have the
selectedindex property available...

so, if the user selects a value in one combo box, to get the selected index
of that combo box I have to do the following
Private Sub TblTimeSheetHoursDataGridView_EditingControlShowin g(ByVal sender
As Object, ByVal e As
System.Windows.Forms.DataGridViewEditingControlSho wingEventArgs) Handles
TblTimeSheetHoursDataGridView.EditingControlShowin g
Dim combo As ComboBox = CType(e.Control, ComboBox)
If (combo IsNot Nothing) Then

Select Case TblTimeSheetHoursDataGridView.CurrentCell.ColumnIn dex
Case 2
RemoveHandler combo.SelectedIndexChanged, _
New EventHandler(AddressOf
EmplCodeComboBox_SelectedIndexChanged)
....
....
....
end sub

Which is all well and good, I now have the selected index of the combo box
the user has just selected. However, I now need to programmatically set the
index of the other combo box....

What i want to know is.....how do I do this (given that the editing control
event had to be raised to get the selected index of the other combo!!).

Surely this is possible somehow!?

Please help

Oct 9 '06 #3
Hi again,

No problems. If you can wait on the problem for another 24 hours, I
will attempt to recreate your problem at home tonight and find an
answer for you. Unfortunately I do not have 2.0 here at work (yes we
are a little behind the times).

Cheers,
Steven

Ausclad wrote:
Im using version 2.0

This is a windows form.

I am using the standard DatagridView. This is bound to a dataset generated
by the dataset designer.

I have gone into the designer for the DataGridView and changed the
properties of the two columns previously mentioned to combo boxes (instead of
text boxes).

On the form load, I create a dataset and use stored procedures to populate
various tables with lookup data.

I then bind the combo boxes in the datagrid to these dataset tables

eg
with DataGridCombo1
.DisplayMember = "EmpCode"
.ValueMember = "Surname"
.DataSource = dsLookups.Tables("EmplsCodeLookup")
end with

now...teh comboboxes that are embedded in the datagrid do not have the
selectedindex property available...

so, if the user selects a value in one combo box, to get the selected index
of that combo box I have to do the following
Private Sub TblTimeSheetHoursDataGridView_EditingControlShowin g(ByVal sender
As Object, ByVal e As
System.Windows.Forms.DataGridViewEditingControlSho wingEventArgs) Handles
TblTimeSheetHoursDataGridView.EditingControlShowin g
Dim combo As ComboBox = CType(e.Control, ComboBox)
If (combo IsNot Nothing) Then

Select Case TblTimeSheetHoursDataGridView.CurrentCell.ColumnIn dex
Case 2
RemoveHandler combo.SelectedIndexChanged, _
New EventHandler(AddressOf
EmplCodeComboBox_SelectedIndexChanged)
...
...
...
end sub

Which is all well and good, I now have the selected index of the combo box
the user has just selected. However, I now need to programmatically set the
index of the other combo box....

What i want to know is.....how do I do this (given that the editing control
event had to be raised to get the selected index of the other combo!!).

Surely this is possible somehow!?

Please help
Oct 9 '06 #4
Ausclad,

If you want help, than give correct questions, the help for a Combobox in a
DataGrid is much more work and completely different than for a DataGridView.

The way you ask your questions gives me not the right feeling to help you.

Maybe the next time, when you let us not first search to a complete
different solution just because you are no lazy to write correctly your
problem.

Just my thought,

Cor

"Ausclad" <Au*****@discussions.microsoft.comschreef in bericht
news:D6**********************************@microsof t.com...
Im using version 2.0

This is a windows form.

I am using the standard DatagridView. This is bound to a dataset
generated
by the dataset designer.

I have gone into the designer for the DataGridView and changed the
properties of the two columns previously mentioned to combo boxes (instead
of
text boxes).

On the form load, I create a dataset and use stored procedures to populate
various tables with lookup data.

I then bind the combo boxes in the datagrid to these dataset tables

eg
with DataGridCombo1
.DisplayMember = "EmpCode"
.ValueMember = "Surname"
.DataSource = dsLookups.Tables("EmplsCodeLookup")
end with

now...teh comboboxes that are embedded in the datagrid do not have the
selectedindex property available...

so, if the user selects a value in one combo box, to get the selected
index
of that combo box I have to do the following
Private Sub TblTimeSheetHoursDataGridView_EditingControlShowin g(ByVal
sender
As Object, ByVal e As
System.Windows.Forms.DataGridViewEditingControlSho wingEventArgs) Handles
TblTimeSheetHoursDataGridView.EditingControlShowin g
Dim combo As ComboBox = CType(e.Control, ComboBox)
If (combo IsNot Nothing) Then

Select Case
TblTimeSheetHoursDataGridView.CurrentCell.ColumnIn dex
Case 2
RemoveHandler combo.SelectedIndexChanged, _
New EventHandler(AddressOf
EmplCodeComboBox_SelectedIndexChanged)
...
...
...
end sub

Which is all well and good, I now have the selected index of the combo box
the user has just selected. However, I now need to programmatically set
the
index of the other combo box....

What i want to know is.....how do I do this (given that the editing
control
event had to be raised to get the selected index of the other combo!!).

Surely this is possible somehow!?

Please help



Oct 9 '06 #5
Wow Cor, I think you came in a little too strong this time.
If you want help, than give correct questions
People can't always word the question as perfectly as we would like.
That's why I asked the clarification questions. Now days, if anyone
ever asks about DataGrids, I always first check what framework version
they are running, just in case. It so happens that this time it paid
off.
I suppose I got lucky...
The way you ask your questions gives me not the right feeling to help you.
I guess thats up to you. You are well within your rights to refuse to
answer anyones questions.
Maybe the next time, when you let us not first search to a complete
different solution just because you are no lazy to write correctly your
problem.
I don't think laziness has anything to do with it in this posting. The
OP merely ommitted a single word "View" that simply happened to have a
large impact on the solution. While I concur that this can be
frustrating, I think a more educational approach for the OP is to
simply advise them of the impact of their error and the consequences.
This lets the OP have a chance at apologising for their mistake. But
coming out and attacking straight off the bat is not going to help
anyone.

Anyway, lets see if we can find an answer for him, shall we? I don't
have .NET2.0 here but I can look at it tonight if no one else can help
now...

Steven

Oct 9 '06 #6
Steven,

I do not like those people who give a lot of work, for the same case I would
have send some links for combobox datagrids and given some help. You can use
the DataGrids in any version of Net.

What is wrong to describe a question good, instead of something as.

"I have a problem with my Combo Boxes in Datagrids" Who says that it is in
this case about Comboboxes and not about a Calendar Control.

It can in my opinion not be a problem. My message was also meant to show to
others that we should not help in these cases that people don't take even
the time to put there question right, in my idea have those people not even
investigated their problems and do I completely agree what Boo often
writes..

But feel free to help.

Cor

"Steven Nagy" <le*********@hotmail.comschreef in bericht
news:11********************@i3g2000cwc.googlegroup s.com...
Wow Cor, I think you came in a little too strong this time.
>If you want help, than give correct questions

People can't always word the question as perfectly as we would like.
That's why I asked the clarification questions. Now days, if anyone
ever asks about DataGrids, I always first check what framework version
they are running, just in case. It so happens that this time it paid
off.
I suppose I got lucky...
>The way you ask your questions gives me not the right feeling to help
you.

I guess thats up to you. You are well within your rights to refuse to
answer anyones questions.
>Maybe the next time, when you let us not first search to a complete
different solution just because you are no lazy to write correctly your
problem.

I don't think laziness has anything to do with it in this posting. The
OP merely ommitted a single word "View" that simply happened to have a
large impact on the solution. While I concur that this can be
frustrating, I think a more educational approach for the OP is to
simply advise them of the impact of their error and the consequences.
This lets the OP have a chance at apologising for their mistake. But
coming out and attacking straight off the bat is not going to help
anyone.

Anyway, lets see if we can find an answer for him, shall we? I don't
have .NET2.0 here but I can look at it tonight if no one else can help
now...

Steven

Oct 9 '06 #7
Well thanks Cor for that complete and utter gibberish.

The whole point of these forums, I thought, was for people who do not have a
complete understanding of the .net framework to seek some guidance from those
who do.

Since I am new to .net I was not aware that there was/is a datagrid and a
datagridview. Since my version only shipped with a DataGridView I (wrongly)
assumed the generic term "datagrid" was adequate. My humble apologies!

Given that I spent a good 5-6 hours attempting this task and googling to
find a solution first I think I have at least given it reasonable thought
before posting the question.

Given the way you write, there no way I could convert my question into
something you could possibly understand anyway.

Steven, thanks for being the kind of person this forum needs. I look
forward to any further help you are able to provide.

thanks
Oct 9 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ausclad | last post: by
4 posts views Thread by Dave | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.