I wish to create a user defined control (which contains a text box and a find button) and place it on a form which has a datagridview. The idea being the user clicks on the column header and inputs search text in the textbox and clicks the find button which uses the dataview.Rowfilter code to bring back the filtered rows.

Now what I need help is to code the user defined search control in such a way that when I drag the control from my toolbox onto the form with a datagridview it should be fully funtionaly i.e no need for me to add any extra coding manually.Is that possible.?

Now, I managed to create the control and was able placed it on my form.I am also able to access the parent form but I am not able to access the dataview of the tabpage on which the datagridview resides. Am I in the right direction or is there a better way to approach this ..?

TIA..

Jayce

You're on the right track. By default when you add new controls via the IDE the Modifiers property is set to private. Open your user control in the IDE and change the Modifiers to Public for any control you want to reference in forms where you are using your user control. The Modifiers property is in the property inspector where you set control name, text, enabled, etc etc.

You're on the right track. By default when you add new controls via the IDE the Modifiers property is set to private. Open your user control in the IDE and change the Modifiers to Public for any control you want to reference in forms where you are using your user control. The Modifiers property is in the property inspector where you set control name, text, enabled, etc etc.

Thanks Scott, your suggestion is useful. However that means everytime I drag and drop my search control on to a form with a datagridview I will have to do manual coding.?
I am looking for a single drag and drop solution without any need for further coding on the parent form... which is why I wanted to do all the coding in the user defined search control itself, so all i have to do is drag and drop and move on.
Is this feasible to do in C# or VB.net? alternatively if you know of any 3rd party tools which can do this pls let me know.. though I hope and believe it can be done in vb.net /c#
Regards
Jayce

There are a number of approaches you could take.

1)
You could add a public property on your user control named "Grid". When you drop the user control on a form then you would select the user control and associate a grid.

2)
You could do basically the same thing as mentioned above but do it with methods at form creation or load time

3)
In your user control you could handle the load event for the control. When the control loads you would programatically find the parent form. You could then search all of the parent forms' controls until you find a grid. You would then have the grid reference in code. This is essentially "plug and play". A drawback to this is if you have two grids on one form --- you wouldn't know which grid to hook up to, unless you wanted to hook up to all grids... This depends on how your control works.

Personally I would add a public property.

Hi Scott,
Thanks for the suggestions. I had already gone down the point #3 approach and evn got reference to the datagridview but got stuck coz I did not know how to extract the dataview (still a newbie in c# & OOP).
But I quite like the first approach, will try that for sure. But may not be able to come back soon as I have been pulled into something else.

Regards
Jayce

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.