8 Replies - 4813 Views - Last Post: 06 July 2012 - 01:23 PM Rate Topic: -----

#1 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 840
  • Joined: 21-December 11

raise control dblClick event

Posted 05 July 2012 - 02:47 PM

Hello! I want to raise double click event of sender object. Is it possible to do something like this:
Private Sub MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DG1.MouseDown,DG2.MouseDown, DG3.MouseDown
Dim CurrentDG As Datagridview = CType(sender, DataGridView)
'Raise event CurrentDG.DoubleClick
End Sub

Is This A Good Question/Topic? 0
  • +

Replies To: raise control dblClick event

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5676
  • View blog
  • Posts: 12,199
  • Joined: 02-June 10

Re: raise control dblClick event

Posted 06 July 2012 - 06:28 AM

I suspect this is a band-aide for getting something else done and its the only way you can think to accomplish what you want.

What is it you really want? If you are trying to call a method then just call it. After all, double-clicking on a gridview should call a method to handle that event. So rather than fake out a double-click just call the same method that the double-click calls.

See Common Tip #4 below.


Some of my common tips (some may apply more than others to your specific style):
  • You have to program as if everything breaks, nothing works, the cyberworld is not perfect, the attached hardware is flakey, the network is slow and unreliable, the harddrive is about to fail, every method will return an error and every user will do their best to break your software. Confirm everything. Range check every value. Make no assumptions or presumptions.

  • Take the extra 3 seconds to rename your controls each time you drag them onto a form. The default names of button1, button2... button54 aren't very helpful. If you rename them right away to something like btnOk, btnCancel, btnSend etc. it helps tremendously when you make the methods for them because they are named after the button by the designer.btnSend_Click(object sender, eventargs e) is a lot easier to maintain than button1_click(object sender, eventargs e)

  • You aren't paying for variable names by the byte. So instead of variables names of a, b, c go ahead and use meaningful names like index, timeOut, row, column and so on. You should avoid 'T' for the timer. Amongst other things 'T' is commonly used throughout C# for Type and this will lead to problems. There are naming guidelines you should follow so your code confirms to industry standards. It makes life much easier on everyone around you, including those of us here to help. If you start using the standards from the beginning you don't have to retrain yourself later.
    You might want to look at some of the naming guidelines. Its a lot easier to start with good habits than to break bad habits later and re-learn.



  • Try to avoid having work actually take place in GUI control event handlers. It is better to have the GUI handler call other methods so those methods can be reused and make the code more readable. This is also how you can send parameters rather than use excessive global variables.
    Spoiler


  • Don't replace lines of code that don't work. Instead comment them out and put your new attemps below that. This will keep you from re-trying the same ideas over and over. Also, when you come back to us saying "I've tried this 100 different ways and still can't get it", we can actually see what you tried. So often a failed attempt is very very close and just needs a little nudge in the right direction. So if we can say "See what you did in attempt 3... blah blah" it helps a lot

    Spoiler

    If you are using Visual Studio you can select a block of lines and hit control+k control+c (Kode Comment) to comment it out. control+k control+u (Kode Uncomment) to uncomment a selected block.

Was This Post Helpful? 1
  • +
  • -

#3 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 498
  • View blog
  • Posts: 3,316
  • Joined: 12-January 10

Re: raise control dblClick event

Posted 06 July 2012 - 06:53 AM

I had replied but the screen switched back to the main screen without posting ughhh...


anyways name your labels it will save you lots of headaches later on in life.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5676
  • View blog
  • Posts: 12,199
  • Joined: 02-June 10

Re: raise control dblClick event

Posted 06 July 2012 - 07:03 AM

View PostDarenR, on 06 July 2012 - 07:53 AM, said:

I had replied but the screen switched back to the main screen without posting ughhh...

This has been happening intermittenly on the site for quite a long time. Anymore I select-all/copy before hitting [post]. That way if it does that I can just paste it back into a reply.

View PostDarenR, on 06 July 2012 - 07:53 AM, said:

anyways name your labels it will save you lots of headaches later on in life.

What are you talking about? The OP doesn't have an labels in their example, just DataGridViews. I agree they could be named better than 1,2,3 (see tip #2 in my post above)
Was This Post Helpful? 0
  • +
  • -

#5 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 498
  • View blog
  • Posts: 3,316
  • Joined: 12-January 10

Re: raise control dblClick event

Posted 06 July 2012 - 07:07 AM

label was just used as a generic term not Label as in the conrtol--- perhaps I should have just said rename your items or controls
Was This Post Helpful? 0
  • +
  • -

#6 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 840
  • Joined: 21-December 11

Re: raise control dblClick event

Posted 06 July 2012 - 07:18 AM

Quote

What is it you really want?

I have 7 datagrids in whole application. I use same mousedown event handler for all datagrids.
Feature of each datagrid is multiselection, drag multiple items, and run file on dblclick. In mouse down event I call dodragdrop if item under mouse arrow is already selected. But when you call DoDragDrop in mouse down then dblclick cant be detected. So I came up with an idea to use timer. Then on mouse down, start timer(it will be enabled only 300-400ms ), then on second mouse down, if timer still "working" call dblclik of that datagrid(sender).

Quote

I suspect this is a band-aide for getting something else done and its the only way you can think to accomplish what you want.

Yes I can call directly dblclick event handler of datagrid(there will be 7 lines of code) , but I am really interested , while I am standing and looking that part of code, is it possible in just one line,simply to raise dblclick event of sender object, it s good to know for the future.

View PostDarenR, on 06 July 2012 - 06:53 AM, said:

anyways name your labels it will save you lots of headaches later on in life.
Thanks, I always do that.
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5676
  • View blog
  • Posts: 12,199
  • Joined: 02-June 10

Re: raise control dblClick event

Posted 06 July 2012 - 07:30 AM

A Timer, or a Stopwatch? A Timer really isn't the right tool for this. A Stopwatch has a higher resolution.

Are you checking the OS value for the span of a double-click so your program matches the user 'feel'?

Quote

In mouse down event I call dodragdrop if item under mouse arrow is already selected.

Maybe the fix for this is not to make up your own double-click but fix this logic. Instead of calling dodragdrop on mousedown event why not call it on mousemove then check if the mouse is down and items are selected?
Was This Post Helpful? 1
  • +
  • -

#8 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: raise control dblClick event

Posted 06 July 2012 - 08:12 AM

< is it possible in just one line,simply to raise dblclick event of sender object

From the msdn doc for the RaiseEvent statement:

Quote

You cannot use RaiseEvent to raise events that are not explicitly declared in the module. For example, if a form has a Click event, you cannot raise its Click event using RaiseEvent. If you declare a Click event in the form module, it shadows the form's own Click event. You can still invoke the form's Click event using normal syntax for calling the event, but not using the RaiseEvent statement.
While RaiseEvent isn't necessarily the only way to go, I would think that if there were another way to raise native events as opposed to calling your handlers that they would mention it here. It looks to me like the answer to your question is no, at least as far as Microsoft is concerned.

This post has been edited by BobRodes: 06 July 2012 - 08:15 AM

Was This Post Helpful? 1
  • +
  • -

#9 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 840
  • Joined: 21-December 11

Re: raise control dblClick event

Posted 06 July 2012 - 01:23 PM

Quote

A Timer, or a Stopwatch? A Timer really isn't the right tool for this. A Stopwatch has a higher resolution.

With timer its working flawless,but yes I will definitely try with stopwatch.

Quote

Maybe the fix for this is not to make up your own double-click but fix this logic. Instead of calling dodragdrop on mousedown event why not call it on mousemove then check if the mouse is down and items are selected?
This was in the first time, but problem is, when the user start dragging(from mouse move) all selected rows become unselected. Solution for this is to store selected rows in the list(in mousedown),and reselect them in mousemove event before DoDragDrop. But when the user start dragging he can see how rows been reselected (this is little annoying, and the feeling is not right). If I start drag in mouse down event, selected rows will stay selected until drag is over, and if I call "reselectrows" AFTER dragging ,"reselecting" is much faster, i dont know why but you cant even notice that they are been reselected. I studied this a lot and finally found the best way. :)I've even try to customize DG by overriding mouse down but after that problems appears like a chain reaction(and dblClick fails also)so I gave up fast.

Quote

Are you checking the OS value for the span of a double-click so your program matches the user 'feel'?
Yes this will be the first thing next.

View PostBobRodes, on 06 July 2012 - 08:12 AM, said:

< is it possible in just one line,simply to raise dblclick event of sender object

From the msdn doc for the RaiseEvent statement:

Quote

You cannot use RaiseEvent to raise events that are not explicitly declared in the module. For example, if a form has a Click event, you cannot raise its Click event using RaiseEvent. If you declare a Click event in the form module, it shadows the form's own Click event. You can still invoke the form's Click event using normal syntax for calling the event, but not using the RaiseEvent statement.
While RaiseEvent isn't necessarily the only way to go, I would think that if there were another way to raise native events as opposed to calling your handlers that they would mention it here. It looks to me like the answer to your question is no, at least as far as Microsoft is concerned.


You cannot use RaiseEvent to raise events that are not explicitly declared in the module.
This is what I was looking for. Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1