Results 1 to 11 of 11

Thread: listview column

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    listview column

    Hello, how to refer to a column created in code for a listview, I need to set it's width property but don't know how to refer to it in code.

    Code:
                lsvOrderDetails.Columns.Clear()
                lsvOrderDetails.Columns.Add("Product")

  2. #2
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: listview column

    You can use the autoresize method

    lsvOrderDetails.AutoResizeColumn(...
    lsvOrderDetails.AutoResizeColumns(...


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  3. #3
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: listview column

    well i am not sure, but doesn't using index help

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: listview column

    I am close but not perfect, works for the headers fine, but not for the contents (cells) of the columns.

    I tried this, works fine for the headers
    Code:
    lsvOrderDetails.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
    but then this is not as good for the contents

    Code:
    lsvOrderDetails.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)

  5. #5
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: listview column

    To answer your initial question, the Add Method returns a column object, which you can then use to reference the column.

    What issue are you having with the resize based on column content?

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: listview column

    Quote Originally Posted by Negative0 View Post
    To answer your initial question, the Add Method returns a column object, which you can then use to reference the column.

    What issue are you having with the resize based on column content?
    I need the content of the listview columns to be fully displayed.

    Quote Originally Posted by Negative0 View Post
    the Add Method returns a column object, which you can then use to reference the column.
    I bet it does, I mean I knew it should, but where can I see it, so I would know how to call it

    or alternatively can I please get an example on how to get the index of the listview columns

    thanks
    Last edited by MrtforCode; Sep 17th, 2009 at 09:38 AM.

  7. #7
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: listview column

    Since it returns a value, you can assign it to a variable:

    Code:
            Dim c As ColumnHeader
            c = ListView1.Columns.Add("hello")
            c.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)

  8. #8
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: listview column

    And for the resize to work properly, you need to call it after the data has been added to the listview.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: listview column

    do you know how to resize all of the columnheaders of the listview, I tried this, it should be something similar pointed to the cells or else...

    Code:
    lsvOrderDetails.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: listview column

    Quote Originally Posted by Negative0 View Post
    And for the resize to work properly, you need to call it after the data has been added to the listview.
    right that could be the cause, give me a few minutes I ll check

    Thanks

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: listview column

    ok, that was the case, now I see it works fine with this:
    Code:
    lsvOrderDetails.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
    but I'll still have to adjust the columns that columnsContents is taking less space than the headers, I guess there is no function that would do the both (headers and the contents)
    will have to work this out
    Last edited by MrtforCode; Sep 17th, 2009 at 09:57 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width