This is a migrated thread and some comments may be shown as answers.
gridview column with different type
7 Answers 2 Views
This is a migrated thread and some comments may be shown as answers.
Moe
Top achievements
Rank 1
Veteran
Moe asked on 17 Sep 2020, 08:59 AM

Hi Admin,

I want to know how to change font for dropdownlist and I put valuemember and displaymember for dropdownlist but after I choose gridview column show valuemember but I don't want . I want dispalymember. One column will be datatime column or textbox column or dropdownlist. 

Below My coding .

 

Imports System
Imports System.Collections.Generic
Imports System.Data
Imports Telerik.WinControls.UI

Public Class RadForm1
    Private Sub RadForm1_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
        With RadGridView1.Columns
            .Add(New GridViewTextBoxColumn("EntityFilingDetailsID") With {.HeaderText = "EntityFilingDetailsID", .IsVisible = False, .VisibleInColumnChooser = False})
            .Add(New GridViewTextBoxColumn("ReportHeading") With {.HeaderText = "Report Heading"})
            .Add(New GridViewTextBoxColumn("FilingDetail") With {.HeaderText = "Filing Detail"})
            .Add(New GridViewTextBoxColumn("EntityFilingValue") With {.HeaderText = "EntityFilingValue"})
            .Add(New GridViewTextBoxColumn("Editor") With {.HeaderText = "EntityFilingValue", .IsVisible = False})
            .Add(New GridViewTextBoxColumn("FieldDataType") With {.HeaderText = "FieldDataType", .IsVisible = False, .VisibleInColumnChooser = False})
            .Add(New GridViewTextBoxColumn("DropDownListData") With {.HeaderText = "DropDownListData", .IsVisible = False, .VisibleInColumnChooser = False})
            .Add(New GridViewTextBoxColumn("IsReadOnly") With {.HeaderText = "IsReadOnly", .IsVisible = False, .VisibleInColumnChooser = False})
        End With

        Dim listofEntityFilingDetails As New List(Of EntityFilingDetails)
        Dim entityFilingDetails As New EntityFilingDetails
        entityFilingDetails.EntityFilingDetailsID = 1
        entityFilingDetails.ReportHeading = "Directed and managed in BVI (Y/N)"
        entityFilingDetails.FilingDetail = "Is the activity directed and managed in the Virgin Islands?"
        entityFilingDetails.EntityFilingValue = "Y"
        entityFilingDetails.FieldDataType = "DropDownList"
        entityFilingDetails.DropdownListData = "Y | N"
        entityFilingDetails.IsReadonly = False
        listofEntityFilingDetails.Add(entityFilingDetails)
        entityFilingDetails = New EntityFilingDetails
        entityFilingDetails.EntityFilingDetailsID = 2
        entityFilingDetails.ReportHeading = "Num Board Meetings"
        entityFilingDetails.FilingDetail = "Number of board meetings the entity held during the financial period with relation to this activity."
        entityFilingDetails.EntityFilingValue = ""
        entityFilingDetails.FieldDataType = "TextBox"
        entityFilingDetails.DropdownListData = ""
        entityFilingDetails.IsReadonly = False
        listofEntityFilingDetails.Add(entityFilingDetails)
        entityFilingDetails = New EntityFilingDetails
        entityFilingDetails.EntityFilingDetailsID = 3
        entityFilingDetails.ReportHeading = "Financial Period Start Date (DD/MM/YYYY)"
        entityFilingDetails.FilingDetail = "Financial Period Start Date"
        entityFilingDetails.EntityFilingValue = ""
        entityFilingDetails.FieldDataType = "DateTimePicker"
        entityFilingDetails.DropdownListData = ""
        entityFilingDetails.IsReadonly = False
        listofEntityFilingDetails.Add(entityFilingDetails)

        entityFilingDetails = New EntityFilingDetails
        entityFilingDetails.EntityFilingDetailsID = 4
        entityFilingDetails.ReportHeading = "Num Board Meetings"
        entityFilingDetails.FilingDetail = "Number of board meetings the entity held during the financial period with relation to this activity."
        entityFilingDetails.EntityFilingValue = "1"
        entityFilingDetails.FieldDataType = "DropDownList"
        entityFilingDetails.DropdownListData = "Countries"
        entityFilingDetails.IsReadonly = True
        listofEntityFilingDetails.Add(entityFilingDetails)
        RadGridView1.DataSource = listofEntityFilingDetails
    End Sub

    Private Sub RadGridView1_EditorRequired(sender As Object, e As EditorRequiredEventArgs) Handles RadGridView1.EditorRequired
        Dim dataRow As GridViewDataRowInfo = TryCast(Me.RadGridView1.CurrentRow, GridViewDataRowInfo)

        If dataRow Is Nothing Then
            Return
        End If

        Dim editor As String = Convert.ToString(dataRow.Cells("FieldDataType").Value)
        Dim DropdownListData As String = Convert.ToString(dataRow.Cells("DropdownListData").Value)
        Dim editorType As Type = e.EditorType

        Select Case editor
            Case "TextBox"
                editorType = GetType(RadTextBoxEditor)
            Case "DateTimePicker"
                editorType = GetType(RadDateTimeEditor)
            Case "DropDownList"
                editorType = GetType(RadDropDownListEditor)
        End Select

        e.EditorType = editorType
    End Sub

    Private Sub radGridView1_CellEditorInitialized(sender As Object, e As GridViewCellEventArgs) Handles RadGridView1.CellEditorInitialized
        If TypeOf e.ActiveEditor Is RadDropDownListEditor Then
            Dim editor As RadDropDownListEditor = TryCast(e.ActiveEditor, RadDropDownListEditor)
            Dim element As RadDropDownListEditorElement = TryCast(editor.EditorElement, RadDropDownListEditorElement)
            Dim DropdownListData As String = Convert.ToString(RadGridView1.CurrentRow.Cells("DropdownListData").Value)
            If DropdownListData = "Y | N" Then
                Dim dt As DataTable = New DataTable()
                dt.Columns.Add("Question")
                dt.Rows.Add("Y")
                dt.Rows.Add("N")
                element.DataSource = dt
                element.DisplayMember = "Question"
                element.ValueMember = "Question"
            Else
                Dim dt As DataTable = New DataTable()
                dt.Columns.Add("CountryName")
                dt.Columns.Add("CountryID")
                dt.Rows.Add("Myanmar", "1")
                dt.Rows.Add("Singapore", "2")
                element.DisplayMember = "CountryID"
                element.ValueMember = "CountryName"
                element.DataSource = dt
            End If
        End If
    End Sub
    Private Sub radGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs) Handles RadGridView1.CellFormatting
        If TypeOf e.CellElement.RowInfo Is GridViewDataRowInfo AndAlso e.Column.Name = "EntityFilingValue" Then
            Dim dateformat As DateTime
            If e.CellElement.RowInfo.Cells("EntityFilingValue").Value IsNot Nothing Then
                If DateTime.TryParse(e.CellElement.RowInfo.Cells("EntityFilingValue").Value.ToString(), dateformat) Then
                    e.CellElement.Text = dateformat.ToString("d MMMM yyyy")
                End If

                If CType(e.Row.Cells("IsReadonly").Value, Boolean) Then
                    e.CellElement.RowInfo.Cells("EntityFilingValue").ReadOnly = True
                Else
                    e.CellElement.RowInfo.Cells("EntityFilingValue").ReadOnly = False
                End If
            End If

            End If



    End Sub
End Class

Public Class EntityFilingDetails
    Property EntityFilingDetailsID As Integer
    Property ReportHeading As String
    Property FilingDetail As String
    Property EntityFilingValue As String
    Property FieldDataType As String
    Property DropdownListData As String
    Property IsReadonly As Boolean

End Class

 

 

 

 


7 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Sep 2020, 12:05 PM
Hello, Moe, 

The EditorRequired event is the appropriate place to change the default editor for a certain column. Thus, in case you are using a GridViewTextBoxColumn, you can replace the text box editor with another one. However, for the RadDropDownListEditor I would recommend you to set the ValueMember property to be the same as the DisplayMember. Thus, both properties will point to the same field from the applied DataSource for the RadDropDownListEditor.

As to the font, it is necessary to handle the VisualItemFormatting event once the editor is initialized: 
    Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'NwindDataSet.Categories' table. You can move, or remove it, as needed.
        Me.CategoriesTableAdapter.Fill(Me.NwindDataSet.Categories)
        'TODO: This line of code loads data into the 'NwindDataSet.Products' table. You can move, or remove it, as needed.
        Me.ProductsTableAdapter.Fill(Me.NwindDataSet.Products)

        Me.RadGridView1.DataSource = Me.ProductsBindingSource

        Dim textColumn As New GridViewTextBoxColumn("MyColumn")
        textColumn.Width = 200
        Me.RadGridView1.Columns.Add(textColumn)

        For Each row As GridViewRowInfo In Me.RadGridView1.Rows
            row.Cells("MyColumn").Value = "Dairy Products"
        Next


        AddHandler Me.RadGridView1.EditorRequired, AddressOf RadGridView1_EditorRequired
        AddHandler Me.RadGridView1.CellEditorInitialized, AddressOf RadGridView1_CellEditorInitialized
    End Sub

    Private Sub RadGridView1_EditorRequired(sender As Object, e As EditorRequiredEventArgs)
        If Me.RadGridView1.CurrentColumn.Name = "MyColumn" Then
            Dim editor As New RadDropDownListEditor()
            Dim element As RadDropDownListEditorElement = TryCast(editor.EditorElement, RadDropDownListEditorElement)
            element.DataSource = Me.CategoriesBindingSource
            element.DisplayMember = "CategoryName"
            element.ValueMember = "CategoryName"
            e.Editor = editor
        End If

    End Sub

    Private Sub RadGridView1_CellEditorInitialized(sender As Object, e As GridViewCellEventArgs)
        Dim editor As RadDropDownListEditor = TryCast(e.ActiveEditor, RadDropDownListEditor)
        If editor IsNot Nothing Then
            Dim element As RadDropDownListEditorElement = TryCast(editor.EditorElement, RadDropDownListEditorElement)
            element.SelectedValue = Me.RadGridView1.CurrentCell.Value
            RemoveHandler element.VisualItemFormatting, AddressOf element_VisualItemFormatting
            AddHandler element.VisualItemFormatting, AddressOf element_VisualItemFormatting
        End If


    End Sub

    Dim f As New Font("Arual", 10.0F, FontStyle.Italic)
    Private Sub element_VisualItemFormatting(sender As Object, args As VisualItemFormattingEventArgs)
        args.VisualItem.Font = f
    End Sub

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Moe
Top achievements
Rank 1
Veteran
answered on 21 Sep 2020, 02:03 AM

HI Dess,

 

If I did same value for display member and value member but database side save value member (only ID save). So what should I do?

 

Thanks

Moe

0
Moe
Top achievements
Rank 1
Veteran
answered on 21 Sep 2020, 03:56 AM

HI Dess,

I want to save ID value only in database. Do you have how to solve these issue ? Please reply me apas.

 

Thanks

Moe

0
Moe
Top achievements
Rank 1
Veteran
answered on 21 Sep 2020, 04:58 AM

Hi Dess,

I have other issue . I already posted last week but nobody not reply to me. 

https://www.telerik.com/account/support-tickets/view-ticket/1477812. 

Thanks

Moe

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Sep 2020, 09:21 AM

Hello, Moe,  

I would like to note that the referred ticket (1477812) is actually a forum thread with 72 hours response time (weekends are excluded). That is why you haven't received a response yet. In addition, note that most of the forum threads are reviewed by Telerik representatives and sometimes we address the questions asked by our customers in the forums as well. However, a post in the forum doesn't guarantee you a response from the Telerik support team. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread. Thank you for your understanding.

As to the question at hand, if you have the ID values stored as cell values, indeed, the RadDropDownListEditorElement.ValueMember should be set to the ID. However, since you don't use a GridViewComboBoxColumn but a GridViewTextBoxColumn, it is expected that the IDs will be displayed in the cells when they are not in edit mode. In order to deal with it, you can handle the RadGridView.CellFormatting event and set the Text property for the cell element according to the ID value each cell from this column stores. 

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

0
Moe
Top achievements
Rank 1
Veteran
answered on 23 Sep 2020, 01:42 AM

Hi Dess,

Can you write for me for example ? I am not sure for that. 

 

Thanks

moe

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Sep 2020, 08:05 AM
Hello, Moe,     

I have prepared a sample project for your reference. Please give it a try and see how it works for your scenario.

Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify and extend it in a way which suits your custom requirements best.

I hope this information helps. If you need any further assistance please don't hesitate to contact me.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Asked by
Moe
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Moe
Top achievements
Rank 1
Veteran
Share this question
or