How do you get a custom control to stay in the toolbox?

Cynolycus 260 Reputation points
2023-06-06T11:11:48.1333333+00:00

I am having all sorts of trouble with a custom control.

All I wanted was a DGV that treated the Enter key as if it were the Tab key.

I followed an article on how to do it and ended up with the CustomDGV in the Solution Explorer and it appeared in the ToolBox also.

I was then able to use it in my project and all seemed fine.

Now it has become a problem because it won't show in the Toolbox and my project is full of errors because of this.

All I have done with the original project since the last time it ran correctly was remove some buttons from a few forms and add a few new ones, rearrange a few controls to make it neater, no code was altered, but now it has this error and won't work anymore.

I have tried resetting the ToolBox which used to work but now it just won't do a thing. I can't rebuild the project because it sees the errors and says to fix these first yet this seems to be the only way to get it back.

Do I have to remove all instances of the customDGV and any reference to it then go through the process of putting them all back just to get the project to work so I can continue creating it?

This happens regularly, sometimes 2 or 3 times each day that I choose to work on it and I have lost hours of work because I have to revert back to a copy that I made then try to get that copy upto date with the one that doesn't work anymore.

I just tried a new project and followed the instructions on

https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-inherit-from-existing-windows-forms-controls?view=netframeworkdesktop-4.8

with a similar result, the custom control appears in the Solution Explorer but won't show in the ToolBox, at least not for a while. I added an existing control to this project which was my customDGV taken from my project that won't work anymore and it ended up in the toolbox of this new project but the customDGV still won't appear in the toolbox of the original project.

Does anybody know how to stop this from happening?

Could this be a problem with Windows 11? I only ask because for the last six months or so I have been having trouble with Windows crashing, blue screen, black screen, restarting for no reason or blank screen like a tv with snow and nothing works.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,755 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-06-06T13:18:26.57+00:00

    Hi

    One possibility would be to use the following code INSTEAD of a Customized DGV. This code seems to do what you want without the complexity.

    	Private Sub DataGridView1_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyDown
    		If e.KeyCode = Keys.Enter Then
    			e.SuppressKeyPress = True
    			SendKeys.Send(vbTab)
    		End If
    	End Sub
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.