c# - Datagridview Cell Selected After ClearSelection -


i have been frustrated weird behavior of datagridview.

when databind-ed, 1 cell gets selected when grid not have focus. have adopted workarounds this

this.activecontrol = textboxpartysearch;  datagridview1.refresh();  datagridview1.clearselection();  datagridview1.currentcell = null;  e.handled = true; 

as suggested in question of mine : remove blue colored row datagridview winforms

but workaround not work , making code messy.

is there other free datagridview available not have problem ?

this works me:

in constructor, after binding set, add handler databindingcomplete event:

dgvcommandos.datasource = systeemcommandos; // = list<> of objects dgvcommandos.databindingcomplete += new datagridviewbindingcompleteeventhandler(dgvcommandos_databindingcomplete); 

the handler:

void dgvcommandos_databindingcomplete(object sender, datagridviewbindingcompleteeventargs e) {     dgvcommandos.clearselection(); } 

if intend select row (e.g. after adding/inserting new object), set:

dgvcommandos.rows[insertpos].selected = true; 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -