Set width of List Box

Discussion in 'AutoCAD' started by KingCAD, Sep 18, 2003.

  1. KingCAD

    KingCAD Guest

    I'm baaack, I have a list box that is populated at run time and I would like to set it's width to be slightly larger that the longest entry.Yet another one of those things that sounds pretty easy, but I ain't found the answer yet.

    Thanks.
    Dave.K
     
    KingCAD, Sep 18, 2003
    #1
  2. If you are using full vb:

    'Declares
    Private Const LB_SETCOLUMNWIDTH = &H195

    Private Declare Function SendMessage Lib _
    "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, _
    lParam As Any) As Long

    'put a button on the form to test with this code:
    Private Sub Command1_Click()
    Dim ColumnWidth As Long 'The Column width in pixels
    ColumnWidth = InputBox("Enter width of columns", , 100)
    SendMessage lstBox.hwnd, LB_SETCOLUMNWIDTH, ColumnWidth, &O0
    End Sub

    Also, go to either http://www.developersdomain.com or
    http://www.mvps.org/vbnet [or any other vb-based site]. They all have
    examples of how to do it.

    ___________________________
    Mike Tuersley
    AutoCAD Clinic
    Rand IMAGINiT Technologies
     
    Mike Tuersley, Sep 18, 2003
    #2
  3. KingCAD

    Norman Yuan Guest

    I think KingCAD's question is really how to determine the length of an entry
    (text string) in ListBox. To set ListBox's width, you can simply
    ListBox1.Width=100, instead of Win32 API call.

    To tell length of text string, though, is a bit difficult to average
    VB/VBAer, and I never did it in VB/VBA, only in .NET (it is fairly easy
    there).
     
    Norman Yuan, Sep 18, 2003
    #3
  4. KingCAD

    KingCAD Guest

    Yes, the question is how to set the list box width to be slightly larger than the longest string in that list box. I know how to set the width with [listbox1.width ="wahtever"] But how do I find out how long the longest string is? Obviously I will have to create some formula to get the actual lebgth I need,(like length of string * 10.625, or so)But I don't know how to get the string length.

    Thanks Guys.
    Dave. K
     
    KingCAD, Sep 18, 2003
    #4
  5. KingCAD

    KingCAD Guest

    Okay, OKAY, so I'm a little slow! I got it,. I guess it was just a little to simple. [Len (Block(Counter).name)]gives me the length of the string then a simple "IF" statement sets a variable to be the length of the longest. DUH!?
    Thanks for the brain jog.
    Dave. K
     
    KingCAD, Sep 18, 2003
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.