|
-
Jun 3rd, 2009, 10:40 PM
#1
Thread Starter
New Member
Changing an existing component
Hello,
I have a large project which consists of about 60 modules. It contains a lot of DataGridView components.
Recently I implemented cut-copy-paste functionality to one of the DataGridViews.
What is the best way to add same functionalities to all the other DataGridViews .
P.S. I don't want to create a new component which inherits DataGridView and re-define all the DataGridViews.
Thanks
Erden
-
Jun 3rd, 2009, 10:52 PM
#2
Re: Changing an existing component
 Originally Posted by Erden
I don't want to create a new component which inherits DataGridView and re-define all the DataGridViews.
That's exactly what you should do. Presumably you have just handled various events and referred directly to your one specific DataGridView in the code you've written. There's no way to reuse that code other than perhaps to copy and paste it multiple times and then fix any errors that generates.
You're using an OO language so you should be using good OOP practices. The correct way to go about this is to create your own class that does the work internally as much as possible and then use that class in multiple places. Doing so will not require you to delete all your existing DataGridViews from your forms and then add new ones. All you would need to do is go into the designer code file for each form that contains a DataGridView and change this:
vb.net Code:
Private DataGridView1 As System.Windows.Forms.DataGridView
Me.DataGridView1 = New System.Windows.Forms.DataGridView
to this:
vb.net Code:
Private DataGridView1 As MyNamespace.MyDerivedDataGridView
Me.DataGridView1 = New MyNamespace.MyDerivedDataGridView
You can then open your forms in the designer and you'll have access to any new properties of your type and you can also handle any new events of your type in code, etc.
-
Jun 3rd, 2009, 10:53 PM
#3
Re: Changing an existing component
The one other option would be to add extension methods to the DataGridView class, which is possible if you're using .NET 3.5. This may not provide all the functionality you need though.
-
Jun 3rd, 2009, 11:12 PM
#4
Thread Starter
New Member
Re: Changing an existing component
 Originally Posted by jmcilhinney
The one other option would be to add extension methods to the DataGridView class, which is possible if you're using .NET 3.5. This may not provide all the functionality you need though.
Thanks a lot! That is What I was looking for. Yes I am using .NET 3.5. But what do you mean by "This may not provide all the functionality you need though." ?
Cheers
-
Jun 3rd, 2009, 11:23 PM
#5
Re: Changing an existing component
 Originally Posted by Erden
But what do you mean by "This may not provide all the functionality you need though." ?
Extension methods can only do so much. They are only methods, for a start. You can't add instance properties or events using extension methods. Also, while they are called as though they are members, they are implemented outside the class, not inside. As such, you have no access to protected members of the class.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|