none
Auto resizing a ListView control based upon the number of data items therein RRS feed

Answers

  • Hi

    It doesn't make sense to have a ListView resize along with the amount of data it has. Consider the size of the Form it is on, you could then have it resize much larger than the Form and disappear off the bottom to points unknown.

    I wonder if you are requiring the ListView to resize along with the Form? If that is the case then you could, for example, set the .Anchor property so that as the Form is resized, the ListView would follow.

    As an example, this would anchor a ListView such that the top left corner remains static and the bottom and right borders follow the Form resizing.

    ListView1.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right

    Alternatively, you can set the ListView .Dock property so that it will autoresize along with the container it is in (such a the Form itself, or a SplitContainer Panel etc). This could be done with

     ListView1.Dock = DockStyle.Fill
    



    Regards Les, Livingston, Scotland

    Friday, May 19, 2017 1:46 PM

All replies

  • Hi

    It doesn't make sense to have a ListView resize along with the amount of data it has. Consider the size of the Form it is on, you could then have it resize much larger than the Form and disappear off the bottom to points unknown.

    I wonder if you are requiring the ListView to resize along with the Form? If that is the case then you could, for example, set the .Anchor property so that as the Form is resized, the ListView would follow.

    As an example, this would anchor a ListView such that the top left corner remains static and the bottom and right borders follow the Form resizing.

    ListView1.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right

    Alternatively, you can set the ListView .Dock property so that it will autoresize along with the container it is in (such a the Form itself, or a SplitContainer Panel etc). This could be done with

     ListView1.Dock = DockStyle.Fill
    



    Regards Les, Livingston, Scotland

    Friday, May 19, 2017 1:46 PM
  • Hi Les,

    Thanks for the reply. Both approaches seem to help! They seem to be mutually exclusive to at least a certain degree, in that when I change the .Dock property, it seems to reset the .Anchor property. In any case, I settled on your .Dock answer, which seems to solve my problem nicely.

    Kind regards,

    Keith

    P.S. Whilst here, in these forums, I have always been unclear as to the appropriate decorum regarding the use of 1) voting a specific response as helpful and 2) marking a specific response as the answer. In the case of your response, you answered it in one, so that was both helpful as well as being the answer. In any case, I have marked both. :)

    P.P.S. Not sure if it is appropriate to ask here, but do you provide personal consulting? I am looking to hire an advanced VB.Net developer for part-time coding work and problem solving.


    R K Howard

    Saturday, May 20, 2017 4:52 PM
  • Hi

    Glad to help.

    It is a very loose system in the marking of answer/vote. My own understanding is that a) if an answer is valid to the OP, then a mark as Answer is useful for others looking for similar questions. b) a vote encourages the poster to keep helping.

    As for consulting. There may well be others here who are both more likely to be of use to you and much more experienced than me.

    I enjoy being helpful, and with that in mind, I would be willing to help if I can.


    Regards Les, Livingston, Scotland


    • Edited by leshay Saturday, May 20, 2017 6:58 PM
    Saturday, May 20, 2017 5:24 PM
  • Hi Les. I emailed you. Please let me know here, only if you did not receive it there. Thanks. Keith

    R K Howard

    Saturday, May 20, 2017 5:40 PM