Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

.Net comboBox problem

Options
  • 25-09-2003 6:19pm
    #1
    Registered Users Posts: 15,443 ✭✭✭✭


    If anyone is using C# or even VB.Net, I have a problem which is driving me insane......maybe someone here can offer me some help.

    Incidentally, the same problem exists (if memory serves) with previous versions of VB, so maybe if anyone knows of a workaround in VB I can apply the same logic here.

    Anyway...the problem....

    I have a combo box which I want to fill in the following manner :

    <2-char-code><seperator><description>

    e.g.
    IE  Ireland
    CH  Switzerland
    D   Germany
    

    Now, given that the default fonts are variable width, this means that the descriptions are not lined up. They will normally appear thusly :

    IE Ireland
    CH Switzerland
    D Germany

    I want the descriptions to line up!

    The first thing I tried was to use a tab character to seperate the code from the text. But guess what....combo-boxes display the tab characer as a non-printing character......so it doesn't work.

    I could switch the combos to use a fixed-width font, but that is just ugly as hell.

    I'm thinking I'll have to resort to writing a custom control to do it myself, or at least turning all my combos of this nature into being ownedrawn and figuring out how to do it the *really* messy way, but I was hoping someone here had a suggestion.

    Aside : Yes, I'm fully aware that the whole point of combo-boxes should be to remove the need for the codes, but this is a customer requirement and I can't convince them to drop it.

    So...any suggestions?

    jc


Comments

  • Registered Users Posts: 437 ✭✭Spunj




  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Unfortunately not, but thanks for the suggestion.

    List boxes honour tabs and therefore allow you to set tabstops.

    Combo boxes do not honour tabs...unless you go to a user-drawn combo, in which case the "drop-down" part will honour tabs, but the "normal" part doesn't!

    The "normal part" is effectively a text box with a button at the end of it. However, normal textboxen don't allow tabs in .net unless you set the "allowsTabs" property....which isn't exposed on the comboBox implementation.

    KHUNT0RZ.

    I've given up and gone with a couple of different design alternatives to present to the customer.

    Now, all I need is a tooltip control that supports decent formatting as well (tab & newline).

    jc


  • Registered Users Posts: 437 ✭✭Spunj


    Doh, I should have read the question :)

    Heres an article that attempts to do at least part of what you are looking for, it may not be exactly what you need but it might give you some more ideas...
    http://www.codeproject.com/cs/combobox/multicolumncombo.asp


  • Registered Users Posts: 3,312 ✭✭✭mr_angry


    As far as I know from my days of Access 2000 programming, you should be able to create a combo-box with multiple columns, and then specify a column width. You'll also have to specify which column is the "bound column". i.e. When an item is selected, this is the value returned by the "entire" combo.


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by mr_angry4
    As far as I know from my days of Access 2000 programming, you should be able to create a combo-box with multiple columns, and then specify a column width. You'll also have to specify which column is the "bound column". i.e. When an item is selected, this is the value returned by the "entire" combo.

    Yup - if I was programming in Access, thats exactly what I would do :)

    Unfortunately, MS in their ultimate wisdom have always given vastly differing component-sets to Access and their "premier" UI tools (previously VB, now the .Net stuff). Whats surprising is that the component-set shipped with Access has always been more powerful in many ways!

    I've given up and gone for a slight redesign. There doesn't seem to be any way around this.

    jc


  • Advertisement
  • Registered Users Posts: 32,417 ✭✭✭✭watty


    If the combo is filled from a ODBC source I have a label beside it with the other info that updates when you change the combo
    Pre  Curr      Country
    [CH][SFR][Switerland   ]
    
    

    You can switch of borders on the labels and have a backgroun label with border
    Pre  Curr      Country
    [CH  SFR][Switerland   ]
    
    


  • Moderators, Science, Health & Environment Moderators Posts: 8,918 Mod ✭✭✭✭mewso


    A tab is effectively a number of spaces or at least you could use a number of spaces:-

    ComboBox1.Items.Add("IE" & " " & "Ireland")

    or create a function

    private function GetTab(size as integer) as string
    dim x as integer
    dim strTab as string
    for x = 1 to size
    strTab &= " "
    next x
    return strTab
    end function

    ComboBox1.Items.Add("IE" & GetTab(5) & "Ireland")

    so that you could easily increase your tab size if necessary.


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Doesn't work with variable-with fonts, as the difference in width between characters is not necessarily the same as the width of a space character.

    Yes, I can get them to *almost* line up using this approach, but thats just not good enough.

    Don't worry about it guys - and thanks for the suggestions - I've abandoned the idea and gone with an alternate approach which is a biy kludgy in my opinion but better from the customer's perspective, so I'm happy.

    Good enough.

    jc


Advertisement