Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box: leading white space 1

Status
Not open for further replies.

cjac

Programmer
Dec 8, 2003
93
GB
Hi, as anyone come across leading whitespace when displaying a list of strings in a combo box? Just can't seem to get rid of it. Any ideas as to what could be causing this? I've got the TextAlign property set to 1-fmtextalignleft - are there any other properties of the combo box that could insert leading whitespace?

Cheers,
cjac
 
Are you sure that the spaces are not part of your string? Have you tried trimming the strings before you add them to the list?

Code:
Combo1.Additem Trim(myString)

zemp
 
How did you fill the combo?
Are you sure that there is no leading space in the source data?
 
I'm already using trim although I'm reading the string in directly via the code as below:

Private Sub cboSearch_Fill()
Dim VSearch1, VSearch2, VSearch3, VSearch4, VSearch5 As String
Dim i As Integer

VSearch1 = "Supanet Username"
VSearch2 = "Account No."
VSearch3 = "Domain"
VSearch4 = "Hosting Username"
VSearch5 = "Sphera ID"
For i = 1 To 5
Trim (Vsearch & i)
Next i
cboSearch(0).AddItem VSearch1
cboSearch(0).AddItem VSearch2
cboSearch(0).AddItem VSearch3
cboSearch(0).AddItem VSearch4
cboSearch(0).AddItem VSearch5

End Sub

All as I can think of is there must be some property associated with the combo box that is aligning the text left.
 
Sorry, I meant aligning the text right!
 
For i = 1 To 5
Trim (Vsearch & i)
Next i

does not do what you think it is doing.

There is no variable called Vsearch, and VB will not add the variable i to the end and 'know' that you mean Vsearch1
Also Trim is a funtion, it returns the trimmed value, rather than changing the passed item directly

If Vsearch was an array, you could use something like
For i = 1 To 5
Vsearch(i) = Trim (Vsearch(i))
Next i


but you are probably best just ditching that bit of code, and doing this:
cboSearch(0).AddItem trim(VSearch1)
cboSearch(0).AddItem trim(VSearch2)
cboSearch(0).AddItem trim(VSearch3)
cboSearch(0).AddItem trim(VSearch4)
cboSearch(0).AddItem trim(VSearch5)


By the way, if you put Option Explicit at the very top of your code module, V would have pointed out the missing variable VSearch for you automatically.

Hope this helps!
 
If you are reading it directly in why bother with the variables.

Code:
Private Sub cboSearch_Fill()

  cboSearch(0).AddItem "Supanet Username"
  cboSearch(0).AddItem "Account No."
  cboSearch(0).AddItem "Domain"
  cboSearch(0).AddItem "Hosting Username"
  cboSearch(0).AddItem "Sphera ID"

End Sub

zemp
 
Cheers Jeff, you're absolutely right in what you're saying with regard to my inappropriate var reference - don't know what I was thinking!
Anyhow, I've used trim on the strings directly like you suggested above, but as I thought, my combo box is still showing leading whitespace. I say "as I thought" because I could see no reason for the trim function being used due to the way my strings are being populated. (although I included it anyway!)
So, it's obviously not a product of the string values, this leaves us with combo box properties I would have thought?
 
Zemp thanks for the post but vb will not allow me to directly add a string value that way. It produces the compile error: "Assignment to constant not permitted."
 
OK.
I just set up a new form, dropped a combo on it and filled it with your strings.
No leading spaces.

So, try this:
Add a new Combo to your form.
That will get the default settings.
rename your old combo as 'Fred'
Rename the new Combo as cboSearch.
To get the (0) bit, you need to put 0 in the Index property.

Then run your code, and see if it looks right.


If no, are you using a standard combo box, such as the one you get when you start a new project?
 
Interesting, I don't get that error.

Another thing, are you using the standard VB combo box? I ask this because I as far as I know the standard combo box does not have a .TextAlign property (mentioned in your original post). Are you referring to a different control? What object does the .TextAlign property belong to?

zemp
 
I think we may be getting somewhere now. I'm using control arrays because of the number of controls on my form - basically doing a tree view and then using frames for each branch on the view - hence lots of objects on my form.
Although I don't think the fact that my combo box is a control array has anything to do with this. I think Zemp may have come up with something though - ie. not the std VB combo box. I'm going to try a std combo box, which I suspect will make all the difference.

Cheers,
cjac
 
Have a star Zemp!
Std combo box now in place and I don't get the problem. I have multiple combo boxes available in my toolbox installed by my predecessor - not sure of the purpose as a combo box is a pretty simple thing in itself. I thought the properties were odd for a combo!
Anyway, thanks for your help guys - a simple problem but one that was irratating me.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top