Alternative to PropertyGrid? Please hear me out

I know this is a broad topic, but please listen to me.

I have some examples where I need to edit a set of related properties. Some of them are free text, others can be an integer or a password, and many others have predefined parameters (selectbox). I basically need a container that repeats lines of text on the left with a control on the right.

I cannot use the PropertyGrid because I do not always have an instance, and I had difficulty understanding all the ipropertyeditorservice attributes and helpers that it wants.

I could not use DataGrid or DataGridView because they are column based. Each row may need a different type of control, so a column full of any type of control is useless.

I tried expanding the ListView where I am stuck right now. The owner draws and draws controls within the second column. This looks fine, but Microsoft's fixed-height issue is a problem. I think this comes from an imaginary or font that even textbox and combobox cannot accept to be sized by themselves and forget about the checklist or something else. I mean, this is usually normal for single-line controls for my specific desktop settings, but I cannot control the overlap at every resolution.

The only idea that I came up with on my own (besides abandoning something non-standard and ugly from System.Windows.Forms.Control) is to hush all these subcontrollers in TableLayoutContainer. It fixes a custom height problem, but I am losing the ListView's title and scroll function.

I have been looking for an alternative for several weeks, and I just can't find it. All invented datagridview and listview-as-datagrid, even commercial solutions. I can’t believe that there is no easy replacement there, which does the PropertyGrid. My ListView is the best of many failures ... what else can I do?

+4
source share
3 answers

Try using 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(); 
+3
source

Have you tried replacing the VisualHint property grid? For information, for a flexible binding of properties, a DataTable can be very convenient if you do not want to study the guts of system.componentmodel

+1
source

I had your problem twice,

For the first time, I inherited a ListBox control and created my own control, it was not an easy task, I had some problems with layout, event focusing, mouse wheel, etc.

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

I think that if I need control again, I will use a third-party control, there are many, I think that ComponentOne has one,

Good luck.

+1
source

All Articles