Results 1 to 4 of 4

Thread: [RESOLVED] [2005] Combobox Question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Resolved [RESOLVED] [2005] Combobox Question

    Hi,

    I have a combobox (coProp) that I have filled with names of people in my database, using and SQL command (not linked to a dataset). I have a hidden combobox (coPropID) that holds the ids of the people in the first combobox, loaded in the same order and linked via a change event so that if the name combobox index changes, the id combobox index will change to the index of the new person's id. Next to the combobox is a button that takes me to another form where I can view and edit details of the person selected in the combobox.

    On returning from editing the person's details, I want any changes to be shown in the combobox. So I am clearing and repopulating the combobox with all the people's details from the database. I then search for the originally selected person's id in the id combobox, find the index of that id and set the selectedindex of the name combobox to the same index. I was hoping that this would display the updated person's details but it still shows the original details.

    Some initial debugging shows that the .Text property of the name combobox is still set to the original details. I tried setting .Text = "" before repopulating the combobox but this then just makes the combobox appear blank.

    Is there a way to show the updated details? My code is below:

    Dim frmPersonDetails As New frmPersonDetails
    frmPersonDetails.ShowDialog() 'go to view/edit person form

    'On return
    Dim selID As String
    Dim ind As Integer
    selID = coPropID.Text
    fillStaffCombo(coProp, coPropID)

    If selID IsNot "" Then
    comboColl = coPropID.Items()
    For Each thisObject As String In comboColl
    If thisObject = selID Then
    ind = coPropID.Items.IndexOf(selID)
    Exit For
    End If
    Next thisObject
    coProp.SelectedIndex = ind
    coProp.Text = coProp.SelectedItem
    End If

  2. #2
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Re: [2005] Combobox Question

    Instead setting combo's Text = "", u better delete that item frm the combo... like:
    VB Code:
    1. Combo.Items.RemoveAt(Combo.SelectedIndex)

    Then you add an item (ie the edite one in the same combo. like:
    VB Code:
    1. Combo.Item.Add(strEditedString)

    I hope it works

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: [2005] Combobox Question

    Thanks, but if I add the edited string, won't it appear twice? the code in fillStaffCombo(coProp, coPropID) clears all items from the combo and re-gets them from the database, so the changed details do appear in the combobox when it is dropped down. It just seems to display the original details in the .Text property.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: [2005] For Loop Problem!

    I've been looking at this some more, I think it is to do with the For Each loop that I am using:

    If selID IsNot "" Then
    comboColl = coPropID.Items()
    For Each thisObject As String In comboColl
    If thisObject = selID Then
    'do nothing and loop to next object in collection
    Else
    ind = coPropID.Items.IndexOf(selID)
    Exit For
    End If
    Next thisObject
    coProp.SelectedIndex = ind
    End If

    comboColl is a collection of items from the coPropID combobox. I wanted to iterate through that collection and compare each item (represented by thisObject) to the value in selID. But instead of comparing, it seems to just assign the value of selID to this Object and therefore sets the coProp.SelectedIndex to -1. Help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width