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
Solved

Combobox selectedindex not changing item

Posted on 2014-01-23
6
1,207 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 33

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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import Data from Multiple Text Files in Excel 12 58
Query group by data in SQL Server - cursor? 3 47
vb.net and creating a class 5 20
How to limit User Input 2 27
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

839 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