Advertisement
Guest User

Untitled

a guest
Aug 9th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1.     public partial class MainForm : Form
  2.     {
  3.         public MainForm()
  4.         {
  5.             var listView = new ListView();
  6.             listView.Dock = DockStyle.Top;
  7.             listView.Height = 200;
  8.  
  9.             var bottomPanel = new Panel();
  10.             bottomPanel.Dock = DockStyle.Fill;
  11.  
  12.             // outer panels
  13.             var group = new Panel();
  14.             var innerGroup = new Panel();
  15.             var innerInnerGroup = new Panel();
  16.  
  17.             // if innerGroup has Anchor = Left | Right | Top | Botton instead of Dock = Fill,
  18.             // scroll position is not reset
  19.             group.Dock = DockStyle.Fill;
  20.             innerGroup.Dock = DockStyle.Fill;
  21.             innerInnerGroup.Dock = DockStyle.Fill;
  22.  
  23.             Controls.Add(group);
  24.             group.Controls.Add(innerGroup);
  25.             innerGroup.Controls.Add(innerInnerGroup);
  26.             innerInnerGroup.Controls.Add(bottomPanel);
  27.             innerInnerGroup.Controls.Add(listView);
  28.  
  29.             // populate listView
  30.             listView.Columns.Add(new ColumnHeader("Column"));
  31.  
  32.             for (int i = 0; i < 100; i++)
  33.             {
  34.                 listView.Items.Add("Item " + i);
  35.             }
  36.  
  37.             // if this little fella has Dock property set to Fill, scroll position is not reset
  38.             var troublemaker = new Panel { BackColor = Color.Blue };
  39.  
  40.             var blankPanel = new Panel { Dock = DockStyle.Fill };
  41.  
  42.             listView.SelectedIndexChanged += (s, e) =>
  43.             {
  44.                 if (listView.SelectedItems.Count == 1)
  45.                 {
  46.                     bottomPanel.Controls.Clear();
  47.                     bottomPanel.Controls.Add(troublemaker);
  48.                 }
  49.                 else
  50.                 {
  51.                     bottomPanel.Controls.Clear();
  52.                     bottomPanel.Controls.Add(blankPanel);
  53.                 }
  54.             };
  55.         }
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement