This is a migrated thread and some comments may be shown as answers.

GridViewComboBoxColumn Value Only Visible on Edit

5 Answers 93 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Crane101
Top achievements
Rank 1
Crane101 asked on 01 Jun 2011, 08:36 AM

Hi,
I have seen variations of this question asked on several different posts, but either the fix has either been irrelevant to my particular situation or the question has gone unanswered. I have created a simplified example that you can run on your own computer, so as to easily demonstrate my problem.

I have a simple class "dog" which contains a property "Breed" of enum type "DogBreeds". I wish to display this value in a GridView combo box, but using more user-friendly text than the enum values.

This is my data class:


Public Class Dog
 
    Private dmName As String
    Private dmColour As String
    Private dmBreed As DogBreeds
 
    Public Sub New(ByVal _name As String, ByVal _colour As String, ByVal _breed As DogBreeds)
        MyBase.New()
        dmName = _name
        dmColour = _colour
        dmBreed = _breed
    End Sub
 
    Public Property Name() As String
        Get
            Return dmName
        End Get
        Set(ByVal value As String)
            dmName = value
        End Set
    End Property
 
    Public Property Colour() As String
        Get
            Return dmColour
        End Get
        Set(ByVal value As String)
            dmColour = value
        End Set
    End Property
 
    Public Property Breed() As DogBreeds
        Get
            Return dmBreed
        End Get
        Set(ByVal value As DogBreeds)
            dmBreed = value
        End Set
    End Property
 
End Class

And my Enum:

Public Enum DogBreeds
    Staff
    Husky
    GShep
End Enum

To demonstrate the problem, create a GridView on a form called "dgv" and add the following code:

'Add some example data      
dogs = New List(Of Dog)
dogs.Add(New Dog("Sacha", "Brown", DogBreeds.Staff))
dogs.Add(New Dog("Nimbus", "Black/Brown", DogBreeds.GShep))
dogs.Add(New Dog("Chinook", "White", DogBreeds.Husky))
 
'Set the grid data source:
dgv.DataSource = dogs
 
'Create the data source for the combo column, comprosed of a column of the enum and a column of the
' "friendly" string represetion for that enum value
Dim dtBreeds As New DataTable
dtBreeds.Columns.Add("BreedEnum", GetType(DogBreeds))
dtBreeds.Columns.Add("BreedName", GetType(String))
dtBreeds.Rows.Add(DogBreeds.GShep, "German Sheppard")
dtBreeds.Rows.Add(DogBreeds.Husky, "Icelandic Husky")
dtBreeds.Rows.Add(DogBreeds.Staff, "Staffordshire Bull Terrier")
 
'Set the column display and value members and the data source for the combo
With DirectCast(dgv.Columns("Breed"), GridViewComboBoxColumn)
        .DisplayMember = "BreedName"
        .ValueMember = "BreedEnum"
        .DataSource = dtBreeds
End With

Run the form. All the combos are blank, but when you click on a combo cell, the correct value is displayed, but disappears again when focus is lost from the cell, so it looks like a display bug. I have successfully used this method on a DataGrid, so not sure why it does not work here.

Any help much appreciated

Shane

5 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 03 Jun 2011, 09:37 AM
Hello Crane101, please find the answer to your question in your previous post regarding the same issue. Please, avoid posting the same question twice as this may slow down our response. Thank you for your understanding.
 
Regards,
Jack
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Eric
Top achievements
Rank 1
answered on 30 Jun 2011, 05:53 AM
I am having the exact same issue, but can't find the earlier thread you are referring to.
0
Jack
Telerik team
answered on 04 Jul 2011, 02:45 PM
Hi Eric,

I am posting here my response to Shane Parker's question:

I confirm that it appears in our latest release and you should be able to use this code to do the job. I logged the issue in our bug tracking system and it will be addressed in one of our upcoming releases. The only solution to work around the issue is to handle the CellFormatting event and set the value manually. Please consider the following sample:
Private Sub radGridView1_CellFormatting(sender As Object, e As CellFormattingEventArgs)
    If e.CellElement.ColumnInfo.Name = "Breed" Then
        If e.CellElement.Value IsNot Nothing Then
            Dim breed As DogBreeds = DirectCast(e.CellElement.Value, DogBreeds)
            e.CellElement.Text = dtBreeds.Rows(CInt(breed))("BreedName").ToString()
        End If
    End If
End Sub

I hope it helps. If you have any questions, do not hesitate to contact us.
 
All the best,
Jack
the Telerik team
Registration for Q2 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting July 18th and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Eric
Top achievements
Rank 1
answered on 07 Jul 2011, 04:40 AM
Hi Jack,

While I am experiencing the same symptoms that Shane Parker did, I am using the Silverlight GridView which does not have a CellFormatting event (or a CellElement.Text property for that matter). Is there a similar workaround on a different event I should try?
I tried handling the CellEditEnding event and manually setting Cell.Value to the NewData value, but that did not do anything.

Thanks again,
Eric

Also, I can read VisualBasic, but I'm using C#. :)
0
Dimitrina
Telerik team
answered on 11 Jul 2011, 02:58 PM
Hi Eric,

As this question is related to another product, would you please post your question in the related Silverlight forum? There you can provide a link to this thread and we will gladly answer your question.

Best wishes,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
GridView
Asked by
Crane101
Top achievements
Rank 1
Answers by
Jack
Telerik team
Eric
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or