Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1192
  • Last Modified:

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.DataGridViewCellPaintingEventArgs) Handles Dg1.CellPainting

        AddTickToSelectionCol(sender, e) 'Add a tick image on the first column of grid
    End Sub

Public Sub AddTickToSelectionCol(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs)
        If e.ColumnIndex = 0 AndAlso e.RowIndex = 0 Then
            e.PaintBackground(e.ClipBounds, False)

            Dim pt As Point = e.CellBounds.Location
            Dim offset As Integer = (e.CellBounds.Width - Me.ImageList1.ImageSize.Width) / 2

            pt.X += offset
            pt.Y = 1
            Me.ImageList1.Draw(e.Graphics, pt, 0)

            e.Handled = True

        End If
    End Sub

The problem is that it disappears on mousehover on the column header.
Any suggestions?
0
RIAS
Asked:
RIAS
  • 8
  • 8
  • 2
1 Solution
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
are your Column Headers Clickable?
0
 
Mohit VijayCommented:
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.
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Also try to set EnableHeadersVisualStyles to false and try again ...
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
RIASAuthor Commented:
oki...cheers will try and get back
0
 
RIASAuthor Commented:
Hi,
Where is RowDatabound event on datagridview ?
0
 
RIASAuthor Commented:
i am using vb.net 2005 windows .Is there any alternative for cell painting to add image in datagridview column header?
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
did you try to set EnableHeadersVisualStyles to false?
0
 
RIASAuthor Commented:
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.
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
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/
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
rowDatabound is for GridView using System.Web.UI.WebControls Namespace
0
 
RIASAuthor Commented:
rowDatabound is for GridView using System.Web.UI.WebControls Namespace
Can I use it in vb.net 2005 windows application?
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
no you can not..DataGridView Is another object ...
You can translate if you want the code of the link i gave you in
http://www.developerfusion.com/tools/convert/csharp-to-vb/
Translate it step by step .not all the code together
0
 
RIASAuthor Commented:
oki trying that..cheers
Struggling on this line
Dim directoryImage As Bitmap = Global.DataGridViewImageHeaderCellElementsSample.Properties.Resources.Directory
 Any ideas on how to pick a image from imagelist ?
 
 
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
a simple code when you ha ve a picture box for example is :
PictureBox1.Image = ImageList1.Images.Item(0)
0
 
Mohit VijayCommented:
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.
0
 
RIASAuthor Commented:
Hi jtoutou,
Converted it but on implementation this line returns nothing
Dim dataGridViewImageColumnHeaderCell As DataGridViewImageColumnHeaderCell = TryCast(dataGridViewTextBoxColumn.HeaderCell, DataGridViewImageColumnHeaderCell)
 
immediate window : ? dataGridViewImageColumnHeaderCell  return : nothing
I know this slightly out of question raised but if you can suggest anything it will be great  Cheers
0
 
RIASAuthor Commented:
Cheers mate.Your solution is invaluable!!!!
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Very Welcome!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 8
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now