Help me understand: DataGrid, returning row clicked

  • Thread starter Thread starter techprot-google04
  • Start date Start date
T

techprot-google04

I used this solution:
http://msdn.microsoft.com/library/d...bconReturningClickedCellValueFromDataGrid.asp

I added the code to my program. And it works great.

What I don't understand is the last part:

this.myDataGrid.MouseDown += new
System.Windows.Forms.MouseEventHandler
(this.myDataGrid_MouseDown);

Of course, I changed "myDataGrid" to the name of the datagrid I'm
using. It works like a charm!

Could someone please help me understand that this code did?
Thanks,
Andrew
 
Hello!
This line of code is registering MouseDown event for the DataGrid. you
will also need a method with signature
private void myDataGrid_MouseDown(object sender,MouseEventArgs e)
obviously you'll need it only if you want to do something when Mouse
button clicks on DataGrid. Otherwise its not at all necessary. If you
are working on events registration from IDE, it'll automatically add
this line to you code. (Analyze Windows Form Designer Generated code).
this.myDataGrid.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.myDataGrid_MouseDown);


Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net
 
Thanks for the response!

I think I got it. Am I right in understanding that the += adds this
event to previously defined events?

-a
 
Actually += is used to consume an event. In other words it wires the
event with your object by creating instance of the appropriate delegate.
-= unwires it. '+=' and '-=' function for events is a bit different than
as an assignment operator.

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net
 
Back
Top