views:

84

answers:

3

I know this is a wide topic, but please hear me out.

I have a few instances where I need to edit a set of related properties. Some are free text, another might be an integer or password, and many more have predefined options (a selectbox). I basically need a container that repeats rows of text on the left with a control on the right.

I can't use a PropertyGrid because I don't always have an instance and I have been having some difficulty understanding all of the ipropertyeditorservice attributes and helpers it wants.

I couldn't use a DataGrid or DataGridView because they're column based. Every row may need a different type of control, so a column full of any one control type is useless.

I tried extending the ListView which is where I'm stuck right now. It's owner drawn and draws the controls within the bounds of the second column. It looks OK, but Microsoft's fixed row height is a problem. I think it goes off the imagelist or the font, which even textbox and combobox can't agree on to size themselves the same way and forget about a checklistbox or anything else. I mean it usually looks OK for single-line controls on my specific desktop settings but I can't control the overlap at every resolution.

The only other idea I've come up with on my own (aside from giving up or deriving something non-standard and ugly from System.Windows.Forms.Control) is to jam all of these subcontrols into a TableLayoutContainer. It fixes the weird height problem mostly but I lose the header and scrolling features of ListView.

I've been looking for an alternative for weeks and I just can't find any. Everybody's reinvented the datagridview and the listview-as-datagrid, even the commercial solutions. I can't believe there isn't a simple replacement out there for what the PropertyGrid does. My ListView is the best of alot of bad lot...what else can I do?

+1  A: 

Have you tried the "VisualHint" property grid replacement? For info, for flexible property binding DataTable can be quite handy if you don't want to learn the guts of system.componentmodel

Marc Gravell
I guess this is about as close as I'll be able to get. I'dve preferred some free source code example but it beats $1000+ for ComponentOne's product at least.
Ryan
+1  A: 

Try using a TableLayoutPanel

Label l1 = new Label();
Label l2 = new Label();
Label l3 = new Label();
Label l4 = new Label();
l1.Text = "Name";
l2.Text = "Color";
l3.Text = "Quantity";
l4.Text = "Notes";
TextBox c1 = new TextBox();
ComboBox c2 = new ComboBox();
NumericUpDown c3 = new NumericUpDown();
TextBox c4 = new TextBox();
c2.Items.AddRange(new string[] { "Red", "Green", "Blue" });

//tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
//tableLayoutPanel1.AutoScroll = true;
tableLayoutPanel1.AutoSize = true;
tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
int rowIndex = 0;
tableLayoutPanel1.SuspendLayout();
foreach (Control[] pair in new Control[][] {
   new Control[] {l1, c1},
   new Control[] {l2, c2},
   new Control[] {l3, c3},
   new Control[] {l4, c4}})
{
   tableLayoutPanel1.Controls.AddRange(pair);
   if (tableLayoutPanel1.RowStyles.Count <= rowIndex)
      tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
   else
      tableLayoutPanel1.RowStyles[rowIndex++].SizeType = SizeType.AutoSize;
}
tableLayoutPanel1.ResumeLayout();
BlueMonkMN
I tried it, nice work, I think it'll be more helpful if it encapsulated with a CustomControl.
Homam
A: 

I had your problem twice,

The first time, I inherited from ListBox control and created my own control, it was not an easy task, I had some problems with the layout, focusing events, mouse wheel and other.

In the second time, I used the PropertyGrid control, but I had also some problems in hiding and disabling some fields if a value has changed in the class,

I think, if I'll need the control again, I'll use a third party control, there're many, I think ComponentOne has one,

Good luck.

Homam