How to create a DataGridViewImageCell - Ranking Column, like in Windows Media Player ?

hello,

i would like to know how to simulate the behavior of the ranking column in media player 10, like when you hover it, stars are on or off, and allows on the fly editing.

the cell values are something like : 0; 75 ; 150; 200; 255
there are 5 values for 5 stars

my question is:

how can i consider it

i mean do i have to create 5 columns , one for each star
or is there a way to insert multiple image items in one cell, I found nothing about it

or shall i simply use 6 versions of image that will not be editable

 

thanks a lot



Answer this question

How to create a DataGridViewImageCell - Ranking Column, like in Windows Media Player ?

  • w_jackson

    i'll tell you whether i did it or not !

    thanks again


  • lwulfers

    Thanks for the above code of TextandImageCell, using it I got the image painted in my datagridviewtextboxcell, now the next thing is  - I have to pop up another form on click event of this image.

    I tried using datagridview cellclick event but it fires everytime when mouse is clicked in any portion of the cell, and doesn't give any information whether image has been clicked or not The cellcontentclick event did not fire when I clicked on the image.

    Please pull me out of this problem as I really need the solution to this, going forth, this image picture click event will be used in lot many places in my code.

    Someone, please help soon.

    Thanks in advance,

    Rajat

     

     



  • Relja Markovic

    Simply Impressed.
    Great Work Done. Smile

  • The_guy_who_whooped_CHUCK

    i've been looking at the code, i have to translate to VB.

    do you think it is possible, or is it time-waisting

    thanks a lot

  • Robbyec

    excellent, exactly what i've been looking for,

    but what do you mean by an unsupported sample

    thank you.


  • El Gato Grande

    Hello,

    I don't understand how can i use this VB code... Could someone have a litle time to explain me.. please!!!

    Step by Step to use this code please!

    I wanted to use this in a datagridview that is showing records from an Access database... The rating is from 1 to 5...

    Help please!



  • Krishna Paripurnam

    Unsupported means that Microsoft (nor I) makes no guarantees or warranties as to how good the sample will perform.

    -mark
    DataGridView Program Manager
    Microsoft
    This post is provided "as-is"

     


  • Rwatking

    Here is an unsupported sample that I created< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    I used the image column as the basis since I'm displaying images. In my custom "rating cell", I override GetFormattedValue to return an image. I created 12 images - 6 images that go from 0 to 5 stars highlighted and another set of images that have a hot-highlight that I use for mouse over: and .

     

    I override the Paint method to identify the star that the mouse is over. The logic to identify which star the mouse is over is a bit conviluted, but it works.

    Anyway, here is the link to the unsupported sample (in c#): http://www.windowsforms.net/blogs/markrideout/RatingCustomDGVColumn.zip

     

    Do note that I did not add keyboard accessibility, only mouse.

     

    -mark

    DataGridView Program Manager

    Microsoft

    This post is provided "as-is"

     

     


  • pritam pathare

    Can Someone convert this code to VB

    I want to use different type of images in a cell but I can only show one of them. I urgently need the solution.


  • PatrickRD

    Hello,

    I tried this and I keep getting this error....

    Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.

    This is how I envoked the class as posted above...

    Dim oCell As New TextAndImageCell

    If oFSEx.IsDirectory Then

    oCell.Image = My.Resources.cfold16.ToBitmap

    Else

    oCell.Image = My.Resources.data16.ToBitmap

    End If

    oCell.Value = oFSEx.Name

    oRow.Cells.Add(oCell)

    oCell = Nothing

    Am I going something wrong Also, I saw the C# class and the TextAndImageCell was part of class TextAndImageColumn. Is that the missing piece

    Thanks in advance.


  • RamMohanRao

    Hi Mark,

    How can I set 0(zero) rating

    Regards
    Vasil


  • kali

    It shouldn't be too hard at all to convert it to VB.

    -mark
    DataGridView Program Manager
    Microsoft
    This post is provided "as-is"

     


  • CWC1980

    here is the vb.net TextAndImageColumn

    Public Class TextAndImageColumn

    Inherits DataGridViewTextBoxColumn

    Private imageValue As Image

    Private imageSize As Size

     

    Public Sub New()

    Me.CellTemplate = New TextAndImageCell

    End Sub

    Public Overloads Overrides Function Clone() As Object

    Dim c As TextAndImageColumn = CType(TryCast(MyBase.Clone, TextAndImageColumn), TextAndImageColumn)

    c.imageValue = Me.imageValue

    c.imageSize = Me.imageSize

    Return c

    End Function

    Public Property Image() As Image

    Get

    Return Me.imageValue

    End Get

    Set(ByVal value As Image)

    If Not Me.Image Is value Then

    Me.imageValue = value

    Me.imageSize = value.Size

    If Not (Me.InheritedStyle Is Nothing) Then

    Dim inheritedPadding As Padding = Me.InheritedStyle.Padding

    Me.DefaultCellStyle.Padding = New Padding(imageSize.Width, inheritedPadding.Top, inheritedPadding.Right, inheritedPadding.Bottom)

    End If

    End If

    End Set

    End Property

    Private ReadOnly Property TextAndImageCellTemplate() As TextAndImageCell

    Get

    Return CType(TryCast(Me.CellTemplate, TextAndImageCell), TextAndImageCell)

    End Get

    End Property

    Friend ReadOnly Property ImageSize_() As Size

    Get

    Return imageSize

    End Get

    End Property

     

    End Class

    Public Class TextAndImageCell

    Inherits DataGridViewTextBoxCell

    Private imageValue As Image

    Private imageSize As Size

    Public Overloads Overrides Function Clone() As Object

    Dim c As TextAndImageCell = CType(TryCast(MyBase.Clone, TextAndImageCell), TextAndImageCell)

    c.imageValue = Me.imageValue

    c.imageSize = Me.imageSize

    Return c

    End Function

    Public Property Image() As Image

    Get

    If Me.OwningColumn Is Nothing OrElse Me.OwningTextAndImageColumn Is Nothing Then

    Return imageValue

    Else

    If Not (Me.imageValue Is Nothing) Then

    Return Me.imageValue

    Else

    Return Me.OwningTextAndImageColumn.Image

    End If

    End If

    End Get

    Set(ByVal value As Image)

    If Not Me.Image Is value Then

    Me.imageValue = value

    Me.imageSize = value.Size

    Dim inheritedPadding As Padding = Me.InheritedStyle.Padding

    Me.Style.Padding = New Padding(imageSize.Width, inheritedPadding.Top + 5, inheritedPadding.Right, inheritedPadding.Bottom)

    End If

    End Set

    End Property

    Protected Overloads Overrides Sub Paint(ByVal graphics As Graphics, ByVal clipBounds As Rectangle, ByVal cellBounds As Rectangle, ByVal rowIndex As Integer, ByVal cellState As DataGridViewElementStates, ByVal value As Object, ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As DataGridViewCellStyle, ByVal advancedBorderStyle As DataGridViewAdvancedBorderStyle, ByVal paintParts As DataGridViewPaintParts)

    MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)

    If Not (Me.Image Is Nothing) Then

    Dim container As System.Drawing.Drawing2D.GraphicsContainer = graphics.BeginContainer

    graphics.SetClip(cellBounds)

    graphics.DrawImageUnscaled(Me.Image, cellBounds.Location)

    graphics.EndContainer(container)

    End If

    End Sub

    Private ReadOnly Property OwningTextAndImageColumn() As TextAndImageColumn

    Get

    Return CType(TryCast(Me.OwningColumn, TextAndImageColumn), TextAndImageColumn)

    End Get

    End Property

    End Class

     

    have fun! :)


  • How to create a DataGridViewImageCell - Ranking Column, like in Windows Media Player ?