Solved

Combobox selectedindex not changing item

Posted on 2014-01-23
6
1,153 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
6 Comments
 
LVL 32

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now