Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Saturday, November 30, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - Controls
Forum to discuss usage & tips for SalesLogix controls and other 3rd party ActiveX controls. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to Controls | New ThreadView:  Search:  
 Author  Thread: Probably a stupid question...but...
Jeff Ballard
Posts: 326
 
Probably a stupid question...but...Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Aug 08 1:40 PM
Is there a way to put both text (visible) and a code (hidden) in a combo box? I'm trying to populate a combo box from a table and want both the code and the value from the table that's my source.

I tried searching the site with google but must not have hit the right keywords...

Thanks,

Jeff
[Reply][Quote]
RJ Samp
Posts: 973
Top 10 forum poster: 973 posts
 
Re: Probably a stupid question...but...Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Aug 08 3:42 PM
No.

Combo boxes hold ONE value......you see this like in SalesProcess where they store the text of the Step in one combo box and the ID field of the Step in another combo box....then lock step the ith position of each box with each other and derive the values from one or tother. So you can use two combo boxes to hold 'related' values....hide one combo box from the user of course.

DataGrids and ListViews can hold multiple values, of course....and you could expose only one or a few columns.....a hidden column could hold the value from the table that's your source.....

[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Probably a stupid question...but...Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Aug 08 4:07 PM
Thx, RJ. I was thinking I could tie two combo boxes together - done it many times in the (old school) web client (although an HTML control could has the code/value paradigm, I needed to sync multiple items; where was ajax when I needed it?). I was hoping to avoid it, but it should work OK in this one instance.

Thanks again...

Jeff
[Reply][Quote]
Thomas Aussem
Posts: 57
 
Re: Probably a stupid question...but...Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Aug 08 1:38 AM
Hi Jeff,

have you ever thought about using the Dictionary Object? Create a Dictionary Object and assign the keys of it to the Combobox. After selecting the combobox item your code has to select the value of that key in the Dictionary object.

I have used that "quick and dirty" workaround a lot of times.

Cheers,
Thomas
[Reply][Quote]
Steve Garner
Posts: 22
 
Re: Probably a stupid question...but...Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Aug 08 6:54 AM
I use an array and fill it while filling the combo items. Since it is loaded with the same index, you can then use the combo itemindex to reference the array.
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Probably a stupid question...but...Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Aug 08 9:17 AM
Thanks, Thomas. Great idea - I didn't even know that VBScript had a dictionary object...a quick google search for "dictionary object vbscript" found this result first: http://www.devguru.com/Technologies/vbscript/QuickRef/dictionary.html - I'll have to take a look at that. I like it better than having a second, hidden object.

Jeff
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Probably a stupid question...but...Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Aug 08 9:20 AM
Thanks, Steve. Another great idea. Between your and Thomas' suggestions I have two great ideas.

Guess I didn't stop long enough to think outside the box...

Jeff
[Reply][Quote]
Ted Sturr
Posts: 78
 
Re: Probably a stupid question...but...Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Aug 08 9:52 AM
Here is a third option that I have used. Sometimes I will add a set of spaces after the text value (something like 50 spaces so there is enough of a gap) and then just put in the ID value at the end of the combobox.text object. Then if I want to have the ID I just pull the Right 12 characters from the combobox text (ie. Right(cbDistributor.Text, 12)). You have to change the combo box style to csDropDownList so it won't try to display the right side of the combobox values.
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Probably a stupid question...but...Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Aug 08 12:29 PM
Another good suggestion - I've used that one in the past.

Here's what I ended up doing - I ended up needing two additional fields besides the primary key, so I took the array approach, but used a multidimensional array.

I discovered something: when you use a Dim statement on an array, it *only* allows an integer - you can't use a variable (I knew that). You also can't ReDim the first element of an multidimensional array - only the last dimension (knew that, too). What I didn't know was that if you don't want to Dim a variable, you can use ReDim in it's place and the "compiler" (ok, syntax checker) will let you have a ReDim with no original Dim statement. I used that to my advantage.

In my loop through the recordset, I get the count of the number of rows while adding my combo box items. After my combo box is populated, I have my ReDim statement with the number of rows and the number of columns I need in my array. The syntax checker was happy with the ReDim in place of the Dim.

The only thing I had to do then was take my array in my "LoadProducts" method and assign it to a form-level variable since I'll need the array outside the "LoadProducts" method. The essential code looks like this:


Option Explicit

Dim ProductId

Sub AXFormOpen(Sender)

Call LoadProducts()

End Sub

Sub LoadProducts

Dim arrayPosition
Dim productCount

arrayPosition = 0
productCount = 0

'**
With .Recordset
If .BOF = False and .EOF = False Then
While .EOF = False
cboProduct.Items.Add .Fields("PRODUCT") & ""
productCount = productCount + 1
.MoveNext()
Wend
End If

.MoveFirst()

'** There is no Dim statment anywhere-only this ReDim
'** A completely dynamically sized array
ReDim tProductId(productCount-1, 1)

For arrayPosition = 0 To productCount-1
tProductId(arrayPosition, 0) = .Fields("PRODUCTID") & ""
tProductId(arrayPosition, 1) = .Fields("CODE") & ""
.MoveNext()
Next
.Close()
End With

ProductId = tProductId '** Assign back to module level variable for use by other code (i.e., cboProductChange

End Sub

Sub cboProductChange(Sender)
Msgbox "code: " & ProductId(cboProduct.ItemIndex, 0) & vbcrlf & "id: " & ProductId(cboProduct.ItemIndex, 1)
End Sub


Thanks to everyone for their help.

Jeff
[Reply][Quote]
Steve Garner
Posts: 22
 
Re: Probably a stupid question...but...Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Aug 08 7:23 AM
Odd, I am able to do the following:

Dim cnt()

... get some data into rst ...

if rst.recordcount > 0 then
ReDim cnt(rst.recordcount)
end if

It also works on multidimensional.

Steve
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Probably a stupid question...but...Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Aug 08 9:24 AM
But with a multidimensional array, you can only redimension the last dimension - I wanted to keep the first dimension as my row, the second as my column. I consider that easier to read. I could have flipped the array but wanted it (r, c), not (c, r).

I had tried doing a generic Dim cnt() but it failed when I tried to ReDim it as a multi-dimensional array. I got an error about the array being locked. It might have been because my array variable was Dim'ed outside the function I was doing the ReDim in. Not really sure...it may have been that or something else. Also, over the years, I've not trusted the recordcount property - usually I've had recordsets that it didn't work.

I just thought it was cool I never actually had to use the Dim statement - I could just get by with a ReDim.

The great thing is that I ran into issues with holding data in memory in a "usable" format (i.e., without a ton of hidden controls, etc.) without having to resort to persistence and am now rebuilding the screen in question as a .NET extension so I can take advantage of real classes, generic lists and some other functionality, possibly datasets.

Jeff
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 11/30/2024 1:23:06 AM