Re: How to re-acquire the Text from a combo box by Mark
Mark
Tue Jan 10 11:20:58 CST 2006
Hello Guys,
I got it working anyway, I will post the results here and see what comments
you have to make
Please note a couple of points,
I had to use the GetItemText method of the combo box to retrive the text
from the value
I then have to pass back into the method it's own selected item, this seems
confusing to me, should it already know it? Especially in a combo box where
there is only one selected item
For what ever reason, if I do not initialise the Selected Text first, I get
two sets of text.
The confirms what I saw in debug mode, I could see the selected text was
correct in debug mode, but the form would not display the selected text.
Here is the routine that updates my form
Private Sub S_PopulateControls()
Me.txtSessionId.Text = mobjRecord.SessionId
S_RefreshComboBox(mobjRecord.PIDTypeId, Me.cboPIDType)
S_RefreshComboBox(mobjRecord.LocalisedTestId, Me.cboLocalisedText)
Me.txtPartNum.Text = mobjRecord.PartNum
End Sub
and here is the code for RefreshCombo
Private Sub S_RefreshComboBox(ByVal int As Integer, ByVal cbo As ComboBox)
cbo.SelectedValue = int
cbo.SelectedText = ""
cbo.SelectedText = cbo.GetItemText(cbo.SelectedItem)
End Sub
Finally, an alternative to this problem is
Dim strText As String
strText = Me.cboPIDType.SelectedText
Me.cboPIDType.SelectedText = ""
Me.cboPIDType.SelectedText = strText
Why do I have to set selected text to "" before it can display it?
Thanks all for any comments, I hope this might be of some help to you guys.
Mark
"Mark L. Breen" <mark.breen@nospam-gmail.com.off> wrote in message
news:%23iRUfqfFGHA.3892@TK2MSFTNGP12.phx.gbl...
> Hello Guys and Galls,
>
> I use combos on my forms.
>
> The code to initialise the combos is as follows
>
> Dim dsPIDTypes As DataSet
> dsPIDTypes = PartDB.GetPIDTypes ' Returns a dataset object
> cboPIDType.DataSource = dsPIDTypes
> cboPIDType.DisplayMember = "tlkpPIDType.PT_Type"
> cboPIDType.ValueMember = "tlkpPIDType.PT_ID"
>
>
> I then have an object that stores the data that is currently displayed on
> the form, it stores the selected value from the combo's, ie,
> mycombobox.SelectedValue
>
> When the user clicks the add button, I make the text of the combo to be =
> ""
>
> However when the user clicks cancel, I want to revert to the values that
> were previously displayed.
>
> For the text boxes, this is easy,
>
> Me.txtDate = objFormData.Date
> Me.txtQty = objFormData.Qty
>
> But then I need to update the text displayed in the combo box.
>
> I can easily do
>
> Me.MyComboBox.SelectedValue = objForm.Product Id
>
> but I want the combo box to display the matching Selected Text.
>
> Is there a way to do this without having to write a query to filter for
> that Product Id ??
>
> I guess what I want is something like
>
> Me.MyComboBox.Text = Me.MyComboBox.Text that corresponds to the selected
> value
>
> Any suggestions?
>
> Marko
>
>
>