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

DataType of Enum and display in grid

5 Answers 666 Views
GridView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 14 Mar 2011, 01:55 PM

Hello,
I have a scenario, where i need some help of you guys.

In this sample application i have created 1 Enum with short datatype.
Also, Enum is flagged enum.
[Flags]
public enum MyType : short
{
    None = 0,
    NseFO = 1,
    BseFO = 2,
    NseCM = 4,
    BseCM = 8,
    NseCD = 16,
    Use = 32,
}

Now i have created below code for generate output as shown in picture attached here.

private void Form1_Load( object sender, EventArgs e )
{
    //DataColumn dt =new DataColumn("Value",typeof (Test));
    //dt.DataType = typeof (Test);
    //dttemp.Columns.Add(dt);
    dttemp1.Columns.Add("ID",typeof(int));
    dttemp1.Columns.Add( "Value", typeof( int ) );
 
    //DataColumn dt = dttemp.Columns["Value"];
    //dt.DataType = typeof (Test);
    ////dttemp.Columns.Add(dt);
 
    dttemp1.Rows.Add(0, 0);
    dttemp1.Rows.Add( 1, 1 );
    dttemp1.Rows.Add( 2, 2 );
    dttemp1.Rows.Add( 3, 3 );
    dttemp1.Rows.Add( 4, 4 );
    dttemp1.Rows.Add( 5, 5 );
 
    temp2 = dttemp1.Clone();
    DataColumn dcolumn = temp2.Columns["Value"];
    dcolumn.DataType = typeof( ExchangeType );
 
    DataTable dtfinal = temp2.Clone();
    foreach( DataRow row in dttemp1.Rows )
    {
        temp2.Rows.Add( row.ItemArray );
    }
 
    DataView filter = new DataView(temp2);
 
    dataGridView1.DataSource = filter;
 
    c1Flex1Grid.DataSource = filter;
 
    radGridView2.DataSource = filter;
}

There is no other event handled here for any other grids.

This simple code producing different out put as shown.

Can you tell me how can i get same output in telerikgridview??????

5 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 14 Mar 2011, 02:09 PM
Hello James,

Please try updating to the latest version, because with the code you have provided, more preciselly with this code:
using System;
using System.Data;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
public partial class Form1 : Form
{
    private RadGridView radGridView1;
    public Form1()
    {
        InitializeComponent();
        this.Controls.Add(radGridView1 = new RadGridView());
        radGridView1.Dock = DockStyle.Fill;
        radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
        var dttemp1 = new DataTable();
        dttemp1.Columns.Add("ID", typeof(int));
        dttemp1.Columns.Add("Value", typeof(int));
 
        //DataColumn dt = dttemp.Columns["Value"];
        //dt.DataType = typeof (Test);
        ////dttemp.Columns.Add(dt);
 
        dttemp1.Rows.Add(0, 0);
        dttemp1.Rows.Add(1, 1);
        dttemp1.Rows.Add(2, 2);
        dttemp1.Rows.Add(3, 3);
        dttemp1.Rows.Add(4, 4);
        dttemp1.Rows.Add(5, 5);
 
        var temp2 = dttemp1.Clone();
        DataColumn dcolumn = temp2.Columns["Value"];
        dcolumn.DataType = typeof(MyType);
 
        DataTable dtfinal = temp2.Clone();
        foreach (DataRow row in dttemp1.Rows)
        {
            temp2.Rows.Add(row.ItemArray);
        }
 
        DataView filter = new DataView(temp2);
 
        radGridView1.DataSource = filter;
    }
 
    [Flags]
    public enum MyType : short
    {
        None = 0,
        NseFO = 1,
        BseFO = 2,
        NseCM = 4,
        BseCM = 8,
        NseCD = 16,
        Use = 32,
    }
}

The result was exactly what you are looking for.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
James
Top achievements
Rank 1
answered on 15 Mar 2011, 12:14 PM
Hey thanks for the reply,

Can you post the image without dropdown list.???
Why there a drop down showing in your output at value column.
Actually its a  result of combination of multiple enum, so theres a no possbility of dropdown.

0
Emanuel Varga
Top achievements
Rank 1
answered on 15 Mar 2011, 02:27 PM
Hello again James,

You have there all the code you need there to reproduce that result.

If you need more help please let me know with what exactly do you need.

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
James
Top achievements
Rank 1
answered on 12 Apr 2011, 01:18 PM
Hello Emanuel,

Recently i have checked this again as per you suggested.
I am attaching screenshot of result.

Check the selected row with ID = 3
You can clearly Spot that c1, and Ms grid showing result which is comma seperated value of two enum.

Why telerik showing it in drop down box??
How can i achieve the same comma seperated value  in telerik instead of dropdown?????
0
Svett
Telerik team
answered on 15 Apr 2011, 09:09 AM
Hi James,

The illustrated behavior happens because RadGridView creates a GridViewComboBoxColumn automatically for the enum type without considering its flag mode. You should create manually a GridViewTextBoxColumn which will have the same behavior as in MS DataGridView:

GridViewTextBoxColumn txtColumn = new GridViewTextBoxColumn("Value", "Value");
txtColumn.DataType = typeof(MyType);
this.radGridView1.Columns.Add(txtColumn);

I considered your concerns as feature request and I added it to our public issue tracking system.

Greetings,

Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
James
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
James
Top achievements
Rank 1
Svett
Telerik team
Share this question
or