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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop down List Box

Status
Not open for further replies.

ami7

Programmer
Oct 3, 2002
48
GB
Hi,

i have drop down list box which basically hold 2 values.(concatenated in my xml schema)

wat i want is to specify the length of the concatenated values.
eg:

Description and Name is concatenated.

Description varies for different names so in my list box if the desc is too big then the name is not visible.
if it is small then both desc and name is displayed.

Is there any way to specify the length of the description to some fixed value. so that i can view both the values.

Pls help.

thanks,
ami.
 
Hey Ami,

What you'd want to do is find out how big the longest description + name is, and then set your ddl's width to allow for that.

D'Arcy
 
Hi d'arcy,

wat i want is to have fixed length for description and then the name should be displayed.

eg:

Description Name
aaaaaaaaaaaaaaaaaaaa bbbbbb

i.e description should always be of this length watever be the data length.The data might exceed this size but still it should display only this much of length.

thanks,
ami.
 
Ahh...ok. Well here's how I'd tackle this one:

First, check the length of the description. if its bigger than the max you want it to be, just grab the characters using something like InString
(Note: I havn't used very many of the string functions, so I'm not 100% that its InString anymore. If you check the VS.NET help on the String class, it can offer more detail I'm sure)

If its smaller than the max you want, I'd use a string builder class to add on extra blank spaces (what is it now...&nbsp? something like that...again, check the help) until it matched the length you want. Something like:

Dim stringbuilder as new stringbuilder
(stringbuilder is part of system.text or system.string I believe)

stringbuilder.append("yourstring")

for i = 1 to CInt(maxlength) - Len(yourstring)
stringbuilder.append("blankspacetermhere")
next

This will build a string that has all the spacing you'll need.

hth

D'Arcy
 
D'arcy,

Thanks for the above info.
two more queries:
as mentd. earlier my listbox contains 2 items.

my code is like this
cmblist.DataSource = emp.Tables(CEmp.EMP_TABLE)
cmblist.DataTextField = CEmp.DESCRIPTION cmblist.DataValueField = CEmp.CODE_FIELD
cmblist.DataBind()


1) How to get the length of the list item value(DESCRIPTION) alone??

2) Howto use the substr function on the dropdownlist value(description)??
syntax for substr is
eg: string.substr(0,3)
how to use this on drop down list value??...


Thanks in advance,
ami.

 
Hey Ami,

1. Are there ever going to be spaces in your Description? If not, then you could just use the Split function (I belive its called) to split the string based on a certain character (in this case the space). then take teh first part of the string split, and get the length.

2. What you'd need to do is go through each item in the ddl, get the value, put it into a string variable, do whatever you want to it, then re-assign the value to the proper index of the ddl

Dim strString as String
For i = 0 to DropDownList.Items.Count - 1
strString = DropDownList.items(i).Value
'do what you want to strString
DropDownList.items(i).Value = strString
Next

hth

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top