locked
Possible for a ListView with "Details" View to have horizontal column wrapping? RRS feed

  • Question

  • Hey Guys,

    I don't think this is possible but I figured I'd ask anyways. I have a listview control that displays data in a "details" view -- there are are number of subitems per listview item, but the subitems displayed are mostly numbers in certain formats, and don't take up very much horizontal space. There are, however, many items in the list view.

    The monitors that this application runs on are all very large (30" Dell's), and have a lot of horizontal space. My rather thin-horizontally data is not best displayed in this list view, as it requires a user to scroll a ton vertically (b/c the listview is only one set of columns wide) despite having tons of blank/unused space on his screen to the right of the data being displayed (assuming the listview takes up the whole Form control).

    What would work best is if the column collection could on-the-fly fill out the blank space on the right (past the used space on the listview). So, rather than one set of columns being displayed in the listview and my user has to scroll down very far vertically to see desired information, if there was enough width in the listview, the listview would allow a second set of columns to appear to the right of the first set, that would display the "next" set of items that the user would see if he had scrolled down a whole view's worth. Same thing if there was enough space for 3 sets of columns -- all 3 would display.

    When the user scrolled down, the top item from the 2nd set would then appear as the last item in the 1st set -- effectively allowing vertical scrolling.

    This would allow for much more data to be displayed at once.

    Is there any functionality in the listview control that allows for this multiple horizontal column-set display?

    Thanks,
    John
    Saturday, August 2, 2008 10:28 PM

Answers

  • That's all quite possible, but you'll have to write the code, LV isn't going to do it automatically.  Start a new WF project, add a new class and paste the code shown below.  Compile.  Drop the new control from the top of the toolbar onto your form.  Add the columns.  Adjust the size of the control to see the effect.  Tweak to code to make it work for you.

    using System;
    using System.Windows.Forms;

    class MyListview : ListView {
      public MyListview() {
        this.View = View.Details;
      }
      protected override void OnResize(EventArgs e) {
        int w = this.ClientSize.Width - SystemInformation.VerticalScrollBarWidth;
        if (this.Columns.Count > 0 && w > 10) {
          int cw = w / this.Columns.Count;
          for (int ix = 0; ix < this.Columns.Count; ++ix) {
            // Handle modulo problem:
            if (ix == this.Columns.Count - 1 && this.Columns.Count > 1)
              cw = w - (this.Columns.Count - 1) * cw;
            this.Columns[ix].Width = cw;
          }
          base.OnResize(e);
        }
      }
    }

    Saturday, August 2, 2008 11:05 PM