locked
How to set ListView column width to fill the whole space? RRS feed

  • Question

  •  <ListView Name="MyListView">
          <ListView.View >
            <GridView >
              <GridViewColumn Header="Name"  
    DisplayMemberBinding="{Binding Path=Name}"/>
               <GridViewColumn Header="Age" DisplayMemberBinding="{Binding Path=Age}"/>
              <GridViewColumn Header="Grade" DisplayMemberBinding=" {Binding Path=Grade}"/>
            </GridView >
          </ListView.View >
        </ListView >


    Now I want to set column width to fill the whole space? How to do it ?

    I want a simple method, easy to understand.

    Thanks a lot ~~~

    Wednesday, August 17, 2011 6:28 AM

Answers

  • Hi Tank,

    U can make use of converter along with converterparameter to achieve this.

    Please find the XAML and CodeBehind attached herewith.

    XAML:

    Code Behind:

    Here ConverterParameter value refers to number of columns ehich in this case is 3. You can change this value based on Number of ur columns.

    Please mark it as an answer if it helps.

    Regards,

    Parth Shah

    • Proposed as answer by parth.shah Wednesday, August 17, 2011 7:11 AM
    • Marked as answer by Tank J Wednesday, August 17, 2011 7:39 AM
    Wednesday, August 17, 2011 7:11 AM
  • Hi again,

    That's true! I find this method, but when I set Width="*", VS 2010 throw an error: can't convert "*" . I also find other methods, but hard to understand.

    FWIW, while a possible work-around, such as the IValueConverter introduced in the thread I linked, might be hard to understand for you, it is a very fundamental and extremely common technique/concept.

    You should thus take the time and grasp the concept behind this - not only will it make your WPF-life a lot easier, it will be one of the key parts that pave your road to success.

    So, with all of the above said, there simply is no simpler to understand alternative in this case (as in many others).


    Cheers,
    Olaf
    http://blogs.intuidev.com
    • Marked as answer by Tank J Wednesday, August 17, 2011 8:31 AM
    Wednesday, August 17, 2011 7:37 AM

All replies

  • Hi there,

    IMHO this is quite an inconsistency as one really should be able to set Width="*" on the column level from XAML; however, that won't work.

    For a work-around, read this thread.


    Cheers,
    Olaf
    http://blogs.intuidev.com
    • Proposed as answer by Rahul P Nath Wednesday, August 17, 2011 7:25 AM
    Wednesday, August 17, 2011 7:00 AM
  • Hi,Olaf

    That's true! I find this method, but when I set Width="*", VS 2010 throw an error: can't convert "*" . I also find other methods, but hard to understand.

    Wednesday, August 17, 2011 7:10 AM
  • Hi Tank,

    U can make use of converter along with converterparameter to achieve this.

    Please find the XAML and CodeBehind attached herewith.

    XAML:

    Code Behind:

    Here ConverterParameter value refers to number of columns ehich in this case is 3. You can change this value based on Number of ur columns.

    Please mark it as an answer if it helps.

    Regards,

    Parth Shah

    • Proposed as answer by parth.shah Wednesday, August 17, 2011 7:11 AM
    • Marked as answer by Tank J Wednesday, August 17, 2011 7:39 AM
    Wednesday, August 17, 2011 7:11 AM
  • Hi again,

    That's true! I find this method, but when I set Width="*", VS 2010 throw an error: can't convert "*" . I also find other methods, but hard to understand.

    FWIW, while a possible work-around, such as the IValueConverter introduced in the thread I linked, might be hard to understand for you, it is a very fundamental and extremely common technique/concept.

    You should thus take the time and grasp the concept behind this - not only will it make your WPF-life a lot easier, it will be one of the key parts that pave your road to success.

    So, with all of the above said, there simply is no simpler to understand alternative in this case (as in many others).


    Cheers,
    Olaf
    http://blogs.intuidev.com
    • Marked as answer by Tank J Wednesday, August 17, 2011 8:31 AM
    Wednesday, August 17, 2011 7:37 AM
  • Hi, Parth.Shah

    Good idea !!  So great~~~

    • Marked as answer by Tank J Wednesday, August 17, 2011 8:32 AM
    • Unmarked as answer by Tank J Wednesday, August 17, 2011 8:33 AM
    Wednesday, August 17, 2011 7:42 AM
  • hi ,Parth Shah

    After using converter ,I slove this problem .But when I change column width, problom still is not sloved~~

    thanks~~~

    Wednesday, August 17, 2011 9:05 AM