winforms - how to create a custom DataGridViewComboBoxCell with floating label on it -
i want have 2 controls in same datagridview column.
i want customize datagridviewcomboboxcell show values of selected value , on floating label text. in past able checkbox , label problem datagridviewcomboboxcell comes out empty datasource when override paint event.
i tried assign datasource again after used paint event although see values in datagridviewcomboboxcell , label showing right value, infinite loop see gui blinking constantly.
10x help.
the code following:
*when form loads
mydgvcheckboxcolumn col = new mydgvcheckboxcolumn(); col.datapropertyname = "value"; col.datasource = list; col.displaymember = "yes"; col.valuemember = "value"; col.defaultcellstyle.alignment = datagridviewcontentalignment.middlecenter; this.datagridview1.columns.add(col); this.datagridview1.rowcount = 50;
the class generic list:
public class checkthis { public string yes { get; set; } public string value { get; set; } public checkthis() { yes = "gggg"; value = "1"; } }
the code custom datagridviewcomboboxcell (i used similar example in past site)
public class mydgvcheckboxcolumn : datagridviewcomboboxcolumn { private string label; public string label { { return label; } set { label = value; } } public override datagridviewcell celltemplate { { return new mydgvcheckboxcell(); } } } public class mydgvcheckboxcell : datagridviewcomboboxcell { private string label; public string label { { return label; } set { label = value; } } protected override void paint(graphics graphics, rectangle clipbounds, rectangle cellbounds, int rowindex, datagridviewelementstates elementstate, object value, object formattedvalue, string errortext, datagridviewcellstyle cellstyle, datagridviewadvancedborderstyle advancedborderstyle, datagridviewpaintparts paintparts) { // base paint implementation paints check box base.paint(graphics, clipbounds, cellbounds, rowindex, elementstate, value, formattedvalue, errortext, cellstyle, advancedborderstyle, paintparts); // check box bounds: content bounds rectangle contentbounds = this.getcontentbounds(rowindex); // compute location want paint string. point stringlocation = new point(); stringlocation.y = cellbounds.y + 30; stringlocation.x = cellbounds.x + contentbounds.bottom; // paint string. var res = false; mydgvcheckboxcolumn col = (mydgvcheckboxcolumn)this.owningcolumn; col.datasource = list; col.displaymember = "yes"; col.valuemember = "value"; this.label = "customer not appear"; graphics.drawstring( this.label, new font("arial", 6, fontstyle.bold), system.drawing.brushes.red, stringlocation); } public object list { get; set; } }
Comments
Post a Comment