KeyDown & MouseDown events by same Subroutine with many Handles..?
hi all.
i have a datagridview in which i want to know which row is selected by mousedown or keydown..
so in both case i want to use only ONE subroutine which can give e.rowindex , e.colindex value of datagridview...
Example..
Code:
Private Sub xyz (s as sender, e as keydownaurguments, m as mousedownaurguments) handles keydown, mousedown
'\\\\ code
end sub
:D Or if possible i want to execute both events in datagridview.cellenter events :D
Code:
Private Sub Datagridview_Cellenter(s as sender, e as ???) handles 1,2,3,.....
msgbox e.rowindex
end sub
(Before post this thread i already fighted with error "because they do not have the same signature" :blush:)
so plz tell me how make its possible...
Re: KeyDown & MouseDown events by same Subroutine with many Handles..?
It seems that all you want is the address of the current cell and you don't really care if it's selected by keyboard or mouse. If that's the case, does the DataGridView.CurrentCellChanged event work for you?
Re: KeyDown & MouseDown events by same Subroutine with many Handles..?
thanks for reply...
stanav i m not focus in only keydown or mousedown event or other events of specific control (it is just a situation or example).. really i want to know; Can we reproduce / redefine any controls events subroutine to handle differents type of other events subroutine...????
if yes then how..
if no then any other method can do this..??
Re: KeyDown & MouseDown events by same Subroutine with many Handles..?
Any method can handle as many different events of as many different objects as you like as long as those events all have the compatible signatures. In previous versions of VB that meant that they had to have the same type for the 'e' parameter. VB 2008 introduces "relaxed delegate conversion", which basically means that the 'e' parameter of the method can either be the same as that of the event or a base type there of. What that means is that a method whose 'e' parameter is type EventArgs can handle any event at all, because EventArgs is the base class for all types used for event handler data.
Having said that, when the 'e' argument is a particular type you will usually want to use one or more members of that type. If the parameter is type EventArgs then you can't directly access those members.
In your case what you're asking for makes no sense. How can you display a message showing the value of e.RowIndex if the event being raised is KeyDown or MouseDown, which have no e.RowIndex property? I think what you need to do is tell us what you're actually trying to achieve because what you've told us doesn't really make sense or indicate that what you want to do is even necessary.