vb.net - DataGridView Handle OnHandleCreate Resetting Selected Rows -
we have microsoft excel com addin creates taskpane user. based on "plug-in" user loads, taskpane populated corresponding usercontrol , displayed on screen.
these usercontrols typically involve use of datagridviews, , save rows user has selected, each time plug-in loaded, selected rows selected user.
however, have found in process of loading usercontrol onto taskpane, , making taskpane visible, several external code methods fire, reset selection of datagridview. below events:
system.windows.forms.dll!system.windows.forms.datagridview.onselectionchanged(system.eventargs e) + 0x88 bytes system.windows.forms.dll!system.windows.forms.datagridview.flushselectionchanged () + 0x37 bytes system.windows.forms.dll!system.windows.forms.datagridview.clearselection(int columnindexexception, int rowindexexception, bool selectexceptionelement) + 0x304 bytes system.windows.forms.dll!system.windows.forms.datagridview.setandselectcurrentcelladdress(int columnindex, int rowindex, bool setanchorcelladdress, bool validatecurrentcell, bool throughmouseclick, bool clearselection, bool forcecurrentcellselection) + 0x60 bytes system.windows.forms.dll!system.windows.forms.datagridview.makefirstdisplayedcellcurrentcell(bool includenewrow) + 0x88 bytes system.windows.forms.dll!system.windows.forms.datagridview.onhandlecreated(system.eventargs e) + 0x3d bytes system.windows.forms.dll!system.windows.forms.control.wmcreate(ref system.windows.forms.message m) + 0x43 bytes system.windows.forms.dll!system.windows.forms.control.wndproc(ref system.windows.forms.message m) + 0x2ed bytes system.windows.forms.dll!system.windows.forms.datagridview.wndproc(ref system.windows.forms.message m) + 0x10a bytes system.windows.forms.dll!system.windows.forms.control.controlnativewindow.onmessage(ref system.windows.forms.message m) + 0x11 bytes system.windows.forms.dll!system.windows.forms.control.controlnativewindow.wndproc(ref system.windows.forms.message m) + 0x39 bytes system.windows.forms.dll!system.windows.forms.nativewindow.debuggablecallback(system.intptr hwnd, int msg, system.intptr wparam, system.intptr lparam) + 0x5e bytes
the actual code more complex , involves calls database, example, shows how create dgv , populate , select rows. below code follow initializecomponents()
method in constructor of usercontrol:
dgvexample.rows.add("actuals") dgvexample.rows.add("budget") dgvexample.rows.add("forecast") dgvexample.rows.add("ly actuals") = 0 dgvexample.rows.count - 1 dgvexample.rows(i).selected = true next
we not want move process of selecting rows after taskpane visible, because user see changes, , not clean end user. makes no sense instantiated dgv object selected rows not hold values once added taskpane.
as had diagnosed, handlecreated event clears selection, solution force handle created @ time of choosing before set selected items. can accomplished 1 of 3 methods:
- reference control handle. if not yet created, force done.
- call control.createhandle
- call control.createcontrol. create handle if control.visible property true.
@tntinmn - forcing creation of control worked. ... idea can cause delayed handle creation?
to answer refer source.
when control create handle? (when control call createwindowex?) control tries as possible defer creating handle. because setting properties forces chatty interop between clr , user32.
typically handles controls created before form.load event called. handles can created if "handle" property called , handle has not yet been created, or createcontrol() called.
Comments
Post a Comment