Solved

Combobox selectedindex not changing item

Posted on 2014-01-23
6
1,268 Views
Last Modified: 2014-01-28
I have two forms, form1 and form2.  

form1 has a combobox, items filled on form load from a linq to Sql Class.   The combobox has a databinding to a text field in a table.

A button on form1 opens form2 (form1 is passed byref to form2).

in form2 the user enters new data which goes to the linq to Sql table, and the combobox items on form1 are cleared and repopulated so adding the new item to the combobox list.

So far so good.

Changing the selectedindex of the combobox on form1 does not change the value shown in the combobox.

Changing the text in the combobox does not change the value shown in the combobox.

I have established that the selectedindex value I am using is correct.

What is the correct way to get the value in the combobox to change to the new value?

Thanks to any responders.
0
Comment
Question by:MattEtiquette
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 34

Expert Comment

by:sarabande
ID: 39806096
for form1 you need to catch the CBN_SELCHANGE event of the combobox control. for form2 the CBN_EDITCHANGE. in the handlers you have to do the needed synchronization.

Sara
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39806152
Setting the SelectedIndex of the combobox to the index of the new value should work. Where have you put this code? Can you show the code you are using to change the selectedindex?
0
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 39807426
Did you have Autopostback set to true in the combobox?? You can try with

Combobox.Items.FindByValue("ValueToLookUp").Selected=True
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:MattEtiquette
ID: 39811644
Some clarification to the above.

The forms are Winforms in a desktop app.

Some code included below.   I am not sure the way I am declaring the form variable is correct.

I have checked that the selected item value is greater than -1 (anum)


    Dim zForm As OrderMain
    Public ContData As New LinqContactDataContext

    Public Sub New(ByRef aform As OrderMain)

        Me.InitializeComponent()
        zForm = aform

    End Sub



                        Try
                            zForm.Contact_nameComboBox.Items.Clear()

                            For Each CTac In ContData.contacts
                                If CTac.org_id = CInt(Me.OrgIdDummyTextBox.Text) Then
                                    zForm.Contact_nameComboBox.Items.Add(CTac.MainName)
                                End If
                                If CTac.contact_id = Me.Contact_idTextBox.Text Then
                                    CurCont = CTac.MainName
                                End If
                            Next
                        Catch ex As Exception
                            MsgBox(ex.Message)
                        End Try

                        aNum = zForm.Contact_nameComboBox.FindStringExact(CurCont)
                        zForm.Contact_nameComboBox.SelectedIndex = zForm.Contact_nameComboBox.FindStringExact(CurCont)
                        zForm.Contact_nameComboBox.Text = CurCont

Open in new window

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39813556
Is the OrderMain already visible by the time you execute this code? If not, try running this code after the form is visible and see if that makes any difference.
0
 

Author Comment

by:MattEtiquette
ID: 39814456
Thanks for the replies.

CodeCruiser pointed me in the right direction, I had some code in the OnActivate event on the OrderMain form that was casuing the problem.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Part One of the two-part Q&A series with MalwareTech.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question