Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields? Formatting a combobox with multiple fields? Formatting a combobox with multiple fields? Formatting a combobox with multiple fields? Formatting a combobox with multiple fields? Formatting a combobox with multiple fields? Formatting a combobox with multiple fields? Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields? Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields?
Go Back  Xtreme Visual Basic Talk > > > Formatting a combobox with multiple fields?


Reply
 
Thread Tools Display Modes
  #1  
Old 01-30-2013, 01:15 PM
Shisno Shisno is offline
Newcomer
 
Join Date: Jan 2013
Posts: 11
Default Formatting a combobox with multiple fields?


How would I format a combobox so that the fields all start at a certain point, or at least are spaced properly?





ex:

SS---SSS---SSSSSSSSS-SSSSSSSSSSSS
SS--SS---SSSSSSSSS-SSSSSSSSSSS
(that's how it's currently lining up)

I need it to be like this:
SS-SSS-SSSSSSS---SSSS
SS-SS--SSSS-------SSSS


(sorry, i'm extremely new to VB... so terminology is "light", haha.)

Ok, auto-format on the forum screwed up my example, I'm going to use -'s as spaces
Reply With Quote
  #2  
Old 01-30-2013, 02:42 PM
Gruff's Avatar
GruffFormatting a combobox with multiple fields? Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

The combobox only displays string data.
It was never meant to display columns of information.

Most fonts are not mono spaced. That is an "i" is narrower than a "M".
So trying to space them into columns does not work either.

I am sure there are third party extended comboboxes that can do what you want but you will have to pay for them.

Have you looked at the listview, or Datagrid control? You could fake a combo dropdown with one of those.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 01-31-2013, 08:13 AM
Shisno Shisno is offline
Newcomer
 
Join Date: Jan 2013
Posts: 11
Default

I have to pull the data from an IBM AS400 data source (using SQL)... there are 4 fields total.
Don't worry, it's a pre-made non-concatenated string (already read up on the devils of SQL concatenation).

Would listview or datarigid work with an SQL command?
Reply With Quote
  #4  
Old 01-31-2013, 09:02 AM
Gruff's Avatar
GruffFormatting a combobox with multiple fields? Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

One other option would be to still use the standard combobox control but use a fixed width font, such as Monotxt. It isn't pretty but you can align characters vertically.

Looking back over your original post brings a couple of questions to mind.
Are you pulling all four fields out as one string or as four strings?

In any case you would have to trim and pad each field with spaces so that the same number of characters define each visual column.

For example the following code produces the attached picture
Code:
Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load ' Define desired column widths in characters Dim ColumnWidths() As Integer = New Integer() {8, 8, 8, 10} ' Fill listbox as sample rows in lieu of a database ListBox1.Items.Add("Cat Mouse Dog Carbon") ListBox1.Items.Add("House Bat Cereal Rag") ListBox1.Items.Add("To Free Seal Woodland") ' Use a mono or fixed width font. ComboBox1.Font = New Font("Monospac821 BT", 8) ' Add lines to the combobox with words aligned into columns. For i As Integer = 0 To 2 Dim s As String = CType(ListBox1.Items(i), String) ComboBox1.Items.Add(ColumnizeWords(s, ColumnWidths)) Next End Sub Private Function ColumnizeWords(Txt As String, ColWidths() As Integer) As String ' Function to isolate words from multiple spaced text. ' Note: Will not work unless the number of words equals the number of columns. ' Also field record of "" or null will cause displayed Column items to be incorrect. Dim sOut As String = "" Dim Segment() As String = Txt.Split(" "c) Dim Col As Integer = 0 For Each s As String In Segment s = s.Trim If s <> "" Then ' Pad the output Dim PaddedSeg As String = s.PadRight(ColWidths(Col), " "c) ' Append to the output sOut &= PaddedSeg 'Increase current column Col += 1 End If Next Return sOut End Function End Class
Attached Images
File Type: png Mono_Spaced_Font_with_Padded_Text.png (33.7 KB, 3 views)
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 02-20-2013 at 10:25 AM.
Reply With Quote
  #5  
Old 01-31-2013, 09:26 AM
Shisno Shisno is offline
Newcomer
 
Join Date: Jan 2013
Posts: 11
Default

I'm pulling all 4 as one SQL command, with only one of the fields being the key.

This is how I currently have it set to display:

ComboBox1.Items.Add(stra + " " + strb + " " + strc + " " + strd)
Reply With Quote
  #6  
Old 01-31-2013, 10:36 AM
Gruff's Avatar
GruffFormatting a combobox with multiple fields? Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

(I made some more edits to my post above.)

Ah! So then if you used a mono spaced (Fixed character width) font and defined your column widths you could display something like I show above.

Since you have no spaces for each item then you could dispense with the function I showed above and just directly pad each item as you add them to the combo box.

ComboBox1.Items.Add(stra.padright(4," "c) & strb.padright(20," "c) & strc.padright(15," "c) & strd.padright(15," "c)

I am just tossing in column widths here. You of course would use whatever makes sense.

BTW "+" is not the operator to use with strings. It can have unexpected results.
Use the "&" operator instead.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #7  
Old 01-31-2013, 11:23 AM
Shisno Shisno is offline
Newcomer
 
Join Date: Jan 2013
Posts: 11
Default

You are awesome, this worked:

ComboBox1.Items.Add(stra.PadRight(10, " "c) & strb.PadRight(6, " "c) & strc.PadRight(10, " "c) & strd.PadRight(10, " "c))

Thanks again... now, just to get my add entry button and form3 to work... going to try and work through it myself, you'll know I didn't succeed if I come back
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields? Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields? Formatting a combobox with multiple fields? Formatting a combobox with multiple fields? Formatting a combobox with multiple fields? Formatting a combobox with multiple fields? Formatting a combobox with multiple fields? Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields?
 
Formatting a combobox with multiple fields?
Formatting a combobox with multiple fields?
 
-->