c# - How do I show errors on a current DataGridViewCheckBoxCell? -
c# - How do I show errors on a current DataGridViewCheckBoxCell? -
i have application in 1 of screens makes heavy utilize of datagridviewcheckboxcells
. in short, have table set in virtualmode
undo scheme involved, validation, , on. in cases doesn't create sense check box box not first checked , on. allow users it, have checking function sets cell's errortext
property , doesn't allow them continue.
blah, blah. i've verified it's not code clearing errortext
or that. problem datagridviewcheckboxcells
not paint error icon / glyph thingy when current cell. cannot reason why designed way. indeed reference source (datagridviewcheckboxcell.cs) backs me up:
in datagridviewcheckboxcell.cs:
protected override rectangle geterroriconbounds(graphics graphics, datagridviewcellstyle cellstyle, int rowindex) { // checks ... point ptcurrentcell = this.datagridview.currentcelladdress; if (ptcurrentcell.x == this.columnindex && ptcurrentcell.y == rowindex && this.datagridview.iscurrentcellineditmode) { // paintprivate not paint error icon if current cell. // don't set erroriconbounds either. homecoming rectangle.empty; } // behavior ... }
and taking @ datagridviewcheckboxcell.paintprivate
:
private rectangle paintprivate(graphics g, rectangle clipbounds, rectangle cellbounds, int rowindex, datagridviewelementstates elementstate, object formattedvalue, string errortext, datagridviewcellstyle cellstyle, datagridviewadvancedborderstyle advancedborderstyle, datagridviewpaintparts paintparts, bool computecontentbounds, bool computeerroriconbounds, bool paint) { // blah blah // here determines "if current cell not draw error icon!" point ptcurrentcell = this.datagridview.currentcelladdress; if (ptcurrentcell.x == this.columnindex && ptcurrentcell.y == rowindex && this.datagridview.iscurrentcellineditmode) { drawerrortext = false; } // sure enough, drawerrortext must true here error icon drawn if (paint && datagridviewcell.painterroricon(paintparts) && drawerrortext && this.datagridview.showcellerrors) { painterroricon(g, cellstyle, rowindex, cellbounds, errorbounds, errortext); } }
how can around this? tried subclass datagridviewcheckboxcell
little avail. there many internal functions , constants can't hit. tried hack in form
uses table, , managed de-select current cell if datagridviewcheckboxcell
after dirtystatechanged
intercepting anyway (for reasons). doesn't work--when user selects cell, sure enough, error icon disappears. can't intercept , block datagridviewcheckboxcell
s beingness selected selectionchanged
, because selection first step in process of editing cell's value.
what can do?
the next code draws "beautiful" error icon in every cell has error text. may have adapt specific case :
static icon m_erroricon; public static icon erroricon { { if (m_erroricon == null) { errorprovider errorprovider = new errorprovider(); m_erroricon = errorprovider.icon; errorprovider.dispose(); } homecoming m_erroricon; } } private void datagridview1_cellpainting(object sender, datagridviewcellpaintingeventargs e) { seek { if ((e.paintparts & datagridviewpaintparts.erroricon) != 0 && !string.isnullorempty(e.errortext)) { icon icon = erroricon; int pixelmargin = 2; rectangle cellbounds = new rectangle(e.cellbounds.x + pixelmargin, e.cellbounds.y, e.cellbounds.width - 2 * pixelmargin, e.cellbounds.height); rectangle firsticonrectangle = new rectangle(cellbounds.left, cellbounds.top + math.max((cellbounds.height - icon.width) / 2, 0), math.min(icon.width, cellbounds.width), math.min(icon.width, cellbounds.height)); e.paint(e.clipbounds, e.paintparts & ~datagridviewpaintparts.erroricon); e.graphics.drawicon(icon, firsticonrectangle); e.handled = true; } } grab (exception exception) { } }
c# winforms datagridview datagridviewcheckboxcell
Comments
Post a Comment