473,796 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetPIDTy pes ' Returns a dataset object
cboPIDType.Data Source = dsPIDTypes
cboPIDType.Disp layMember = "tlkpPIDType.PT _Type"
cboPIDType.Valu eMember = "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.Sele ctedValue

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.Dat e
Me.txtQty = objFormData.Qty

But then I need to update the text displayed in the combo box.

I can easily do

Me.MyComboBox.S electedValue = 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.T ext = Me.MyComboBox.T ext that corresponds to the selected
value

Any suggestions?

Marko

Jan 10 '06 #1
4 1767
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********@nos pam-gmail.com.off> wrote in message
news:%2******** ********@TK2MSF TNGP12.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.GetPIDTy pes ' Returns a dataset object
cboPIDType.Data Source = dsPIDTypes
cboPIDType.Disp layMember = "tlkpPIDType.PT _Type"
cboPIDType.Valu eMember = "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.Sele ctedValue

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.Dat e
Me.txtQty = objFormData.Qty

But then I need to update the text displayed in the combo box.

I can easily do

Me.MyComboBox.S electedValue = 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.T ext = Me.MyComboBox.T ext that corresponds to the selected
value

Any suggestions?

Marko

Jan 10 '06 #2
Hi,

"Mark L. Breen" <ma********@nos pam-gmail.com.off> wrote in message
news:%2******** ********@TK2MSF TNGP12.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.GetPIDTy pes ' Returns a dataset object
cboPIDType.Data Source = dsPIDTypes
cboPIDType.Disp layMember = "tlkpPIDType.PT _Type"
cboPIDType.Valu eMember = "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.Sele ctedValue

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.Dat e
Me.txtQty = objFormData.Qty

But then I need to update the text displayed in the combo box.

I can easily do

Me.MyComboBox.S electedValue = 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.Select edIndex = -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.T ext = Me.MyComboBox.T ext 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_PopulateContr ols()
Me.txtSessionId .Text = mobjRecord.Sess ionId

S_RefreshComboB ox(mobjRecord.P IDTypeId, Me.cboPIDType)

S_RefreshComboB ox(mobjRecord.L ocalisedTestId, Me.cboLocalised Text)

Me.txtPartNum.T ext = mobjRecord.Part Num

End Sub
and here is the code for RefreshCombo

Private Sub S_RefreshComboB ox(ByVal int As Integer, ByVal cbo As ComboBox)

cbo.SelectedVal ue = int

cbo.SelectedTex t = ""

cbo.SelectedTex t = cbo.GetItemText (cbo.SelectedIt em)

End Sub

Finally, an alternative to this problem is

Dim strText As String
strText = Me.cboPIDType.S electedText
Me.cboPIDType.S electedText = ""
Me.cboPIDType.S electedText = 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********@nos pam-gmail.com.off> wrote in message
news:%2******** ********@TK2MSF TNGP12.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.GetPIDTy pes ' Returns a dataset object
cboPIDType.Data Source = dsPIDTypes
cboPIDType.Disp layMember = "tlkpPIDType.PT _Type"
cboPIDType.Valu eMember = "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.Sele ctedValue

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.Dat e
Me.txtQty = objFormData.Qty

But then I need to update the text displayed in the combo box.

I can easily do

Me.MyComboBox.S electedValue = 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.T ext = Me.MyComboBox.T ext 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.S electedText = Me.cboPIDType.S electedText

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

Mark
"ME" <tr*********@co mcast.netREMOVE THIS> 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********@nos pam-gmail.com.off> wrote in message
news:%2******** ********@TK2MSF TNGP12.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.GetPIDTy pes ' Returns a dataset object
cboPIDType.Data Source = dsPIDTypes
cboPIDType.Disp layMember = "tlkpPIDType.PT _Type"
cboPIDType.Valu eMember = "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.Sele ctedValue

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.Dat e
Me.txtQty = objFormData.Qty

But then I need to update the text displayed in the combo box.

I can easily do

Me.MyComboBox.S electedValue = 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.T ext = Me.MyComboBox.T ext 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
4324
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 be better to promote better programming than rely on PHP to compensate for lazy programming?
4
6430
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 well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
1
4101
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 for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR>
11
4012
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
18543
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 blocks until something.exe terminates. Just what I /don't/ want. (Wouldn't an & be nice here! Sigh) I need something.exe to disconnect and run in the background while I
1
3705
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 sockets??
8
4420
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 image, which will upload the record to a mySql db so users can then either view all profiles or query.. I.e. show all males in UK, all femails over 35 etc. Now, I'm not asking for How to do this but more what would be the best way? I've looked at...
8
3661
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 say that i like it to see mysql replaced by a real database (stored procedures etc.)
1
3640
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 NOT IN ( SELECT manufacturers_id FROM products )
3
3493
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 the variable $GET but $GET is not a variable, I thought it came from the page that calls the PHP file? if(($_GET)==""){ this gets an error
0
10465
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.