473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to re-acquire the Text from a combo box

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

Jan 10 '06 #1
4 1748
ME
If you are relying on the SelectedValue of the combo box to be set the best
way to perform your action is to use the SelectedIndex property of the combo
box. When the SelectedIndex property changes the combo updates itself as
though that item had been "selected" by the user (it even fires the event
associated with it), in other words both the SelectedValue and the
SelectedItem are updated in tandum.

Typically the easiest way to get the correct SelectedIndex is to enumerate
the datasource of the combo box and determine the appropriate index to use.
Remeber that SelectedIndex is the index of the ITEM IN THE LIST, it is NOT
the index or key you may have bound using the ValueMember.

For example:

say the data source looks like this (where column A is the Primary Key):
A | B
1 | Joe
3 | Jim
5 | Jon
6 | Jaq

If you wanted "Jim" displayed in the combo box you would set the
SelectedIndex property to 1, Because "Jim" is the second item in the list.
SelectedIndex begins counting at Zero (0), hence the items are indexed by
the combo list as 0, 1, 2, 3 and so on.

Thanks,

Matt

"Mark L. Breen" <ma********@nospam-gmail.com.off> wrote in message
news:%2****************@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

Jan 10 '06 #2
Hi,

"Mark L. Breen" <ma********@nospam-gmail.com.off> wrote in message
news:%2****************@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.
It will show the matching display value when you assign the (old)
SelectedValue. But only if you don't use CombBox.Text="" to clear it like
you're doing, instead to clear it you must use:

ComboBox.SelectedIndex = -1 (Twice in NET1.1 because of a bug.)
HTH,
Greetings

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

Jan 10 '06 #3
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" <ma********@nospam-gmail.com.off> wrote in message
news:%2****************@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

Jan 10 '06 #4
Hello Matt,

Thanks for that,

I have just found another, my third solution.

This seems silly, but now I have

Me.cboPIDType.SelectedText = Me.cboPIDType.SelectedText

I know, I am saying let 1=1, but this action seems to refresh the combo.

Mark
"ME" <tr*********@comcast.netREMOVETHIS> wrote in message
news:-d********************@comcast.com...
If you are relying on the SelectedValue of the combo box to be set the
best way to perform your action is to use the SelectedIndex property of
the combo box. When the SelectedIndex property changes the combo updates
itself as though that item had been "selected" by the user (it even fires
the event associated with it), in other words both the SelectedValue and
the SelectedItem are updated in tandum.

Typically the easiest way to get the correct SelectedIndex is to enumerate
the datasource of the combo box and determine the appropriate index to
use. Remeber that SelectedIndex is the index of the ITEM IN THE LIST, it
is NOT the index or key you may have bound using the ValueMember.

For example:

say the data source looks like this (where column A is the Primary Key):
A | B
1 | Joe
3 | Jim
5 | Jon
6 | Jaq

If you wanted "Jim" displayed in the combo box you would set the
SelectedIndex property to 1, Because "Jim" is the second item in the list.
SelectedIndex begins counting at Zero (0), hence the items are indexed by
the combo list as 0, 1, 2, 3 and so on.

Thanks,

Matt

"Mark L. Breen" <ma********@nospam-gmail.com.off> wrote in message
news:%2****************@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


Jan 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would...
4
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
1
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with...
8
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
8
by: Lothar Scholz | last post by:
Because PHP5 does not include the mysql extension any more is there a chance that we will see more Providers offering webspace with Firebird or Postgres Databases ? What is your opinion ? I must...
1
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id ...
3
by: presspley | last post by:
I have bought the book on advanced dreamweaver and PHP recently. I have installed MySQL and PHP server but am getting an error on the $GET statement show below. It says there is a problem with...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.