msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with programmatically adding combo boxes

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise
Author Message
cdmunoz



Joined: 04 Oct 2007
Posts: 3

PostPosted: Wed Sep 26, 2007 1:24 pm    Post subject: Problem with programmatically adding combo boxes Reply with quote

I have created a sub routine for programmatically add an indefinite number of
combo boxes to a form. The combo boxes are bound in code to a view for
displaying the available options. This routine works good until you add the
second combo box. At that point it changes the first combo box's selected
item. A third changes the second and first and so on. I've tried setting
the combo box name and tag to a unique name, but that doesn't help. How can
I make each iteration behave separately?
--
Cindy

Archived from group: microsoft>public>vb>enterprise
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 1081

PostPosted: Wed Sep 26, 2007 1:29 pm    Post subject: Re: Problem with programmatically adding combo boxes Reply with quote

"cdmunoz" wrote in message @microsoft.com...
>I have created a sub routine for programmatically add an indefinite number
>of
> combo boxes to a form. The combo boxes are bound in code to a view for
> displaying the available options. This routine works good until you add
> the
> second combo box. At that point it changes the first combo box's selected
> item. A third changes the second and first and so on. I've tried setting
> the combo box name and tag to a unique name, but that doesn't help. How
> can
> I make each iteration behave separately?

What version of VB?

Show some code.
Back to top
View user's profile Send private message
cdmunoz



Joined: 04 Oct 2007
Posts: 3

PostPosted: Wed Sep 26, 2007 3:48 pm    Post subject: Re: Problem with programmatically adding combo boxes Reply with quote

Sorry, guess I should have stated that...I'm using Microsoft Visual Studio 2005

Here's the code for the routine:
Private Sub SetNewCombo(ByVal CControl As Control, ByVal ControlName As
String, ByVal Datafield As String, ByVal DisplayField As String, Optional
ByVal SourceField As String = "", Optional ByVal DataSource As DataView =
Nothing, Optional ByVal DefaultValue As String = "")

Try
Dim lCombo As New ComboBox

With lCombo
.Name = ControlName 'Predefined as "Filter1Combo" and the
number of the added control
.Font = gFont
.Size = New Size(140, 20)
.Location = New Point(6, mintHeight)
.DisplayMember = DisplayField
.ValueMember = Datafield
.Tag = ControlName
.Visible = True

Dim lCol1, lCol2 As New DataColumn

lCol1.DefaultValue = DisplayField
lCol2.DefaultValue = Datafield

.Items.Add(lCol1)
.Items.Add(lCol2)

'Set Data
.DataSource = DataSource

'Set default value
If DefaultValue.Length > 0 Then
.SelectedValue = DefaultValue
End If

End With

CControl.Controls.Add(lCombo)

Catch ex As Exception
MsgBox("SetNewCombo: " & ex.Message)

End Try

End Sub

As I stated, the creation of the controls works great, but after selecting
the value and you add another combo box, it resets the previous box's value
to the new box value.
--
Cindy


"Bob Butler" wrote:

> "cdmunoz" wrote in message
> @microsoft.com...
> >I have created a sub routine for programmatically add an indefinite number
> >of
> > combo boxes to a form. The combo boxes are bound in code to a view for
> > displaying the available options. This routine works good until you add
> > the
> > second combo box. At that point it changes the first combo box's selected
> > item. A third changes the second and first and so on. I've tried setting
> > the combo box name and tag to a unique name, but that doesn't help. How
> > can
> > I make each iteration behave separately?
>
> What version of VB?
>
> Show some code.
>
>
Back to top
View user's profile Send private message
Ken Halter



Joined: 04 Oct 2007
Posts: 4150

PostPosted: Wed Sep 26, 2007 3:59 pm    Post subject: Re: Problem with programmatically adding combo boxes Reply with quote

"cdmunoz" wrote in message @microsoft.com...
> Sorry, guess I should have stated that...I'm using Microsoft Visual Studio
> 2005

Yeah... in that case, you'll want to post to a group that contains "dotNet"
in its name. All groups on the MS server that start with
"microsoft.public.vb" are for pre-dotNet versions of VB. None of that code
would work in VB6 (can't change the name of a control at runtime, for one
thing)

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm
Back to top
View user's profile Send private message
cdmunoz



Joined: 04 Oct 2007
Posts: 3

PostPosted: Wed Sep 26, 2007 4:38 pm    Post subject: Re: Problem with programmatically adding combo boxes Reply with quote

Okay, thanks.
--
Cindy


"Ken Halter" wrote:

> "cdmunoz" wrote in message
> @microsoft.com...
> > Sorry, guess I should have stated that...I'm using Microsoft Visual Studio
> > 2005
>
> Yeah... in that case, you'll want to post to a group that contains "dotNet"
> in its name. All groups on the MS server that start with
> "microsoft.public.vb" are for pre-dotNet versions of VB. None of that code
> would work in VB6 (can't change the name of a control at runtime, for one
> thing)
>
> --
> Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
> In Loving Memory - http://www.vbsight.com/Remembrance.htm
>
>
>

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group