Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I apologize in advance as I'm still new to programming in VB. I am trying to create a custom DataGridView control that has filtering textboxes/comboboxes and an image in the header cells. I've created a CustomHeaderCell class and have been able to add the image by overriding the Paint event, but I cannot seem to add any controls. I've seen a couple examples in C#, but I haven't had any luck translating it to VB.NET.

I think I'm supposed to add the textbox/combobox and eventhandlers in the Paint Event as well, but all I have been able to do is draw images & rectangles. I'm using Visual Studio 2015. Any help would be greatly appreciated!!

What I have tried:

Public Class CustomGridHeaderCell
Inherits DataGridViewColumnHeaderCell
Public Textbox As New TextBox
Protected Overrides Sub Paint(graphics As Graphics, clipBounds As Rectangle, cellBounds As Rectangle, rowIndex As Integer, dataGridViewElementState As DataGridViewElementStates, value As Object, formattedValue As Object, errorText As String, cellStyle As DataGridViewCellStyle, advancedBorderStyle As DataGridViewAdvancedBorderStyle, paintParts As DataGridViewPaintParts)
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)
Dim Textbox As New TextBox
Textbox.Name = "Textbox"
Textbox.Location = New Point(100, 0)
Textbox.Height = (cellBounds.Height - 2) / 2
Textbox.Width = cellBounds.Width - 2
Textbox.BackColor = Color.Red
Textbox.CreateControl()
End Sub
End Class
Posted
Updated 10-Feb-22 20:31pm

1 solution

Hello ,

custom controls by Vb are compound by Forms , Controls and inheritance.

The Graphic object is a wrong way.

You can custom a Controls by modifying one, and adding properties or attributes from one other, for sure.

Graphics and Draws are really for 'all that is visible'.

Your code try to melt 'Native Textbox' with a twik base on coordinates, in a DgHeaderCell. It's a heavy approach.

Dig Microsoft Documentation about Controls, and way to inherits them.
You'll put a 4k movie player in a button soon. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900