I have a mydatagridview class which inherits from the built-in DataGridView control, as shown below:
public class mydatagridview : DataGridView
{
protected override bool ProcessDataGridViewKey(KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.ProcessTabKey(e.KeyData);
return true;
}
return base.ProcessDataGridViewKey(e);
}
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.Enter)
{
this.ProcessTabKey(keyData);
return true;
}
return base.ProcessDialogKey(keyData);
}
}
Now I want to utilize it in my main class:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
I want to Utilize myDatagridview with Datagridview1 of : public partial class Form1 : Form
How can I do this?
You need to create an instance of your custom control class, and then add that instance to your form’s
Controlscollection. For example:Of course, you could also do the same thing from the Designer. It will automatically insert code very similar to that shown above inside the
InitializeComponent()method.If your custom control doesn’t show up in the Toolbox automatically after you’ve rebuilt your project, make sure that you’ve enabled toolbox auto-population:
From the "Tools" menu, select "Options".
Expand the "Windows Forms Designer" category.
Set the "AutoToolboxPopulate" property to True.