RIAS
asked on
Datagridview columnheader image disappears on mouse hover
Hi,
I have added a image in datagridview columnheader on cell painting event
Private Sub Dg1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataG ridViewCel lPaintingE ventArgs) Handles Dg1.CellPainting
AddTickToSelectionCol(send er, e) 'Add a tick image on the first column of grid
End Sub
Public Sub AddTickToSelectionCol(ByVa l sender As Object, ByVal e As System.Windows.Forms.DataG ridViewCel lPaintingE ventArgs)
If e.ColumnIndex = 0 AndAlso e.RowIndex = 0 Then
e.PaintBackground(e.ClipBo unds, False)
Dim pt As Point = e.CellBounds.Location
Dim offset As Integer = (e.CellBounds.Width - Me.ImageList1.ImageSize.Wi dth) / 2
pt.X += offset
pt.Y = 1
Me.ImageList1.Draw(e.Graph ics, pt, 0)
e.Handled = True
End If
End Sub
The problem is that it disappears on mousehover on the column header.
Any suggestions?
I have added a image in datagridview columnheader on cell painting event
Private Sub Dg1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataG
AddTickToSelectionCol(send
End Sub
Public Sub AddTickToSelectionCol(ByVa
If e.ColumnIndex = 0 AndAlso e.RowIndex = 0 Then
e.PaintBackground(e.ClipBo
Dim pt As Point = e.CellBounds.Location
Dim offset As Integer = (e.CellBounds.Width - Me.ImageList1.ImageSize.Wi
pt.X += offset
pt.Y = 1
Me.ImageList1.Draw(e.Graph
e.Handled = True
End If
End Sub
The problem is that it disappears on mousehover on the column header.
Any suggestions?
are your Column Headers Clickable?
Can you write this code on RowDatabound event?
there you can apply a check for header row.
paint event again fire when you mouse over on header, that why during mouse over, it again n again n again try to paint/add tick on header, that's why its looks like that disappear.
there you can apply a check for header row.
paint event again fire when you mouse over on header, that why during mouse over, it again n again n again try to paint/add tick on header, that's why its looks like that disappear.
Also try to set EnableHeadersVisualStyles to false and try again ...
ASKER
oki...cheers will try and get back
ASKER
Hi,
Where is RowDatabound event on datagridview ?
Where is RowDatabound event on datagridview ?
ASKER
i am using vb.net 2005 windows .Is there any alternative for cell painting to add image in datagridview column header?
did you try to set EnableHeadersVisualStyles to false?
ASKER
Hi jtoutou,
Did try it and it worked.Just looking for an alternative for cell paint as VjSoft suggested it keeps on firing on and off.
If I get no answer to the alternative I will surely accept your solution.Cheers for that.
Did try it and it worked.Just looking for an alternative for cell paint as VjSoft suggested it keeps on firing on and off.
If I get no answer to the alternative I will surely accept your solution.Cheers for that.
no....there is an implementation also using Cell Paint...
Take a look here it is a large code in C ...
http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/daaf033d-8160-4990-ae7e-8d8af20426b9/
Take a look here it is a large code in C ...
http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/daaf033d-8160-4990-ae7e-8d8af20426b9/
rowDatabound is for GridView using System.Web.UI.WebControls Namespace
ASKER
rowDatabound is for GridView using System.Web.UI.WebControls Namespace
Can I use it in vb.net 2005 windows application?
Can I use it in vb.net 2005 windows application?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oki trying that..cheers
Struggling on this line
Dim directoryImage As Bitmap = Global.DataGridViewImageHe aderCellEl ementsSamp le.Propert ies.Resour ces.Direct ory
Any ideas on how to pick a image from imagelist ?
Struggling on this line
Dim directoryImage As Bitmap = Global.DataGridViewImageHe
Any ideas on how to pick a image from imagelist ?
a simple code when you ha ve a picture box for example is :
PictureBox1.Image = ImageList1.Images.Item(0)
PictureBox1.Image = ImageList1.Images.Item(0)
Sorry for late response, you can find RowDataBound for gridview from below url
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx
You can generate this events by open page designer mode, select grid view, right click on it check properties, go into event tab, there you will find rowdatabound event.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx
You can generate this events by open page designer mode, select grid view, right click on it check properties, go into event tab, there you will find rowdatabound event.
ASKER
Hi jtoutou,
Converted it but on implementation this line returns nothing
Dim dataGridViewImageColumnHea derCell As DataGridViewImageColumnHea derCell = TryCast(dataGridViewTextBo xColumn.He aderCell, DataGridViewImageColumnHea derCell)
immediate window : ? dataGridViewImageColumnHea derCell return : nothing
I know this slightly out of question raised but if you can suggest anything it will be great Cheers
Converted it but on implementation this line returns nothing
Dim dataGridViewImageColumnHea
immediate window : ? dataGridViewImageColumnHea
I know this slightly out of question raised but if you can suggest anything it will be great Cheers
ASKER
Cheers mate.Your solution is invaluable!!!!
Very Welcome!!!