CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2005
    Location
    Eden Prairie, MN
    Posts
    18

    CListCtrl: variable columns per row?

    Is there a way to vary the number and types of controls in each column/row?

    In the attached mockup, the Settings column can have any of the following based on what's selected in the Main column:

    - three edit text controls (row 1 in the mockup)
    - a dropdown menu (rows 2 and 3)
    - one dropdown menu, one button, and one edit text control (row 4)

    Is this even possible? If so, how would you approach it?
    I've combed through all the CListCtrl articles and haven't seen anything like it.

    I'm already familiar with how to implement different types of controls in different columns if a CListCtrl, just not how to vary it by row.
    Attached Images Attached Images  

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: CListCtrl: variable columns per row?

    Are you sure that what you see on this image is a ListCtrl?
    Use Spy++ and see what is the window class of this control.
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2005
    Location
    Eden Prairie, MN
    Posts
    18

    Re: CListCtrl: variable columns per row?

    Victor, this is just a graphical mockup of what I would like to achieve. Please ignore the style and appearance of the controls; the graphic was created to illustrate the desired layout and functionality only. I do plan to implement it as a CListCtrl, assuming I can figure out how to get Column 2 to support different controls based on what's selected in Column 1. Any advice in that regard would be greatly appreciated!

  4. #4
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: CListCtrl: variable columns per row?

    The CListCtrl cannot do what you want. You better start with a plain CWnd to do your own control or you also can use an ownerdrawn CListBox as base class which already would support scrolling and would allow you to place as many additionally 'controls' for each row as you want.

  5. #5
    Join Date
    Jan 2011
    Posts
    26

    Re: CListCtrl: variable columns per row?

    I agreed with itsmeandnobodyelse.

    I have try on so many way to play with CListCtrl.
    On your proposal, you better off with starting with CWnd.

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: CListCtrl: variable columns per row?

    Agree as well with above posters...

    A CListCtrl is not "a generic control that has columns and rows". It's how many people would perceive it as, but it isn't that.

    Windows controls exhibit a certain behaviour and if what you want doesn't fit that particular behaviour the windows control isn't the one you want, regardless of how much it visually looks like it.
    The behaviour for a listcontrol is to display a list of tabular data (mostly text) and allow users to select items in this list.
    There is some side behaviour, like drag and drop and label editing, but the above is what a listcontrol is.

    You can usually fairly easily make windowscontrols appear visually different, but changing their intended and inate behaviour is often extremely hard or even impossible to change. More often than not, trying to enforce unintended behaviour will end up giving you a control that users will intuitively find "strange/annoying" to use.


    What you want is probably more akin to certain advanced grid controls that allow you to attach controls to cells. You could write the entire control yourself, or buy a library that offers what you need.

    You could also be stubborn and try to enforce this into a CListcontrol, and with a lot of work and headaches, you can probably end up with something that will "more or less" do what you want, sufficient that you find it acceptable, but that your users are very likely going to hate.

  7. #7
    Join Date
    Apr 2005
    Location
    Eden Prairie, MN
    Posts
    18

    Re: CListCtrl: variable columns per row?

    Thanks so much for the replies! Your advice has probably saved me quite a bit of time and frustration. I especially appreciate the deeper explanation, OReubens, and am starting to look into 3rd party libraries. No sense reinventing the wheel.

    Do you have any specific libraries in mind? I'm thinking maybe JUCE, but have barely scratched the surface of what it has to offer.

  8. #8
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: CListCtrl: variable columns per row?

    I don't really have much experience using third party UI libraries. If what I need isn't suited for one of the windows controls, we usually refactor the problem so that it does fit into standard controls, or if really necessary, we create a custom control of our own.

    The issue here is that if a custom control was important enough for this particular application that you needed a custom control, you better be sure that you can rely on it being maintained into the future. That usually ends up meaning "make it yourself". or at the least "get sourcecode" so you can fix issues if need be.

    I only really have knowledge of one third party control which is objective grid from roguewave. It could probably achieve what you're after. It's quite elaborate and even goes so far that you can embed entire grids as a single cell into another bigger grid. (it's not a very cheap solution though).

  9. #9
    Join Date
    Apr 2005
    Location
    Eden Prairie, MN
    Posts
    18

    Re: CListCtrl: variable columns per row?

    Just to follow up, this example has been quite helpful. Obviously it doesn't gift-wrap and deliver exactly what I need, but it's at least helped me get started down the path of creating my own custom controls within the CListCtrl.

    http://www.codeguru.com/cpp/cpp/cpp_...istcontrol.htm

Tags for this Thread

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

Featured