c# - Fix row height of every row in TableLayoutPanel -
i'm working on windows c#.
firstly, things can not alter need following:
the size oftablelayoutpanel
fixed. the total # of columns fixed. now, want set prepare height rows increasing rows, if set rowstyle
property percent
100.0f
works fine 3 4 items, after 4-5 items, command on 1 row overwrites controls on row.
i have searched more i'm not able proper answer. have tried autosize
, percent
, absolute
properties of rowstyle
, though not working.
so , how? how can accomplish this?
ultimately, want same datagridview
of windows c#.
thanks in advance....
i'm working on winforms...the sample code here..
int cnt = tablelayout.rowcount = mydatatable.rows.count; tablelayout.size = new system.drawing.size(555, 200); (int = 1; <= cnt; i++) { label lblsrno = new label(); lblsrno.text = i.tostring(); textbox txt = new textbox(); txt.text = ""; txt.size = new system.drawing.size(69, 20); tablelayout.controls.add(lblsrno, 0, - 1); tablelayout.controls.add(txt, 1, - 1); } tablelayout.rowstyles.clear(); foreach (rowstyle rs in tablelayout.rowstyles) tablelayout.rowstyles.add(new rowstyle(sizetype.autosize));
the label , textboxes working fine 4-5 #of rows whenever #of row(in case, variable cnt in loop) increases, rows overwriting each other 1 command overwrite another...i had drag-drop tablelayoutpanel command , created 1 row , 2 columns manually.
so please tell me how it.
i'm still new tablelayoutpanels myself, noticed @ bottom of code, you're clearing rowstyles collection, you're trying iterate through them in foreach loop.
you did this:
tablelayout.rowstyles.clear(); //now have 0 rowstyles foreach (rowstyle rs in tablelayout.rowstyles) //this never execute tablelayout.rowstyles.add(new rowstyle(sizetype.autosize));
try instead.
tablelayoutrowstylecollection styles = tablelayout.rowstyles; foreach (rowstyle style in styles){ // set row height 20 pixels. style.sizetype = sizetype.absolute; style.height = 20; }
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
edit: realized adding n rows doesn't add together n rowstyles can iterate through. think what's happening you're adding n rows, none of them have rowstyles.
i suppose can clear() rowstyles, add together n rowstyles similar how you're doing.
c# winforms tablelayoutpanel row-height
No comments:
Post a Comment