c# - Abort sorting in DataGridView when row has been edited -
i have datagridview 2 columns. sortmode of first set automatic.
in grid lot rows, , when change value in row, example xyz abc still in position row was. edited row jumps top.
i want abort automatic sorting , want call sorting left click on column. be
i found solution (code below + set sortmode programmatically), row still jumping :/ has solution tackle issue?
private void datagridview1_columnheadermouseclick(object sender, datagridviewcellmouseeventargs e) { if (e.button == mousebuttons.left) { datagridviewcolumn newcolumn = datagridview1.columns[e.columnindex]; sortorder direction; if (datagridview1.sortorder == sortorder.ascending) { datagridview1.sort(newcolumn, listsortdirection.ascending); direction = sortorder.ascending; } else { datagridview1.sort(newcolumn, listsortdirection.descending); direction = sortorder.descending; } newcolumn.headercell.sortglyphdirection = direction; } }
why don't disable sorting when capturing edit event of datagridview ?
private void datagridview1_cellbeginedit(object sender, datagridviewcellcanceleventargs e) { foreach (datagridviewcolumn column in datagridview1.columns) column.sortmode = datagridviewcolumnsortmode.notsortable; }
then restore sorting reverting behavior (by restoring again in rightclick event of column or whatever context menu item or other)
Comments
Post a Comment