Home Forums WinForms controls Xceed Grid for WinForms displaying enum in grid

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13187 |

    Hey Everyone –

    I can’t for the life of me figure out how to display the string value of an enum type in the grid, I can only seem to access its int value.

    For example, if I have the following enum

    public enum Example : int
    {
    A = 1,
    B = 2
    }

    How could I tell the column displaying this enum to show the string value or how can I add a combobox that lets me choose which to set the cell as?

    Thanks in advance.

    Craig

    Imported from legacy forums. Posted by csperler (had 3330 views)

    User (Old forums)
    Member
    Post count: 23064

    I haven’t tested this code, but I found it on The Code Project:

    Array values = Enum.GetValues(typeof(Example)); // Example is the enum-type here
    combo.DataSource = values;

    http://www.thecodeproject.com/csharp/EnumDataSource.asp?msg=883690#xx883690xx

    Imported from legacy forums. Posted by Tommy (had 265 views)

    User (Old forums)
    Member
    Post count: 23064

    This will work:

    public enum Example : int
    {
    A = 1,
    B = 2
    }

    Xceed.Grid.Editors.GridComboBox status_comboEditor =
    new Xceed.Grid.Editors.GridComboBox();

    Xceed.Grid.Editors.GridComboBox status_comboViewer = new Xceed.Grid.Editors.GridComboBox();

    ArrayList refTypeAL = new ArrayList();
    refTypeAL.Add(new DictionaryEntry(Example.A, “A”));
    refTypeAL.Add(new DictionaryEntry(Example.B, “B”));

    status_comboEditor.DataSource = refTypeAL;
    status_comboEditor.ValueMember = “Key”;
    status_comboEditor.DisplayMember = “Value”;
    status_comboEditor.DropDownWidth = 400;
    status_comboEditor.TabStop = false;

    status_comboViewer.DataSource = refTypeAL;
    status_comboViewer.ValueMember = “Key”;
    status_comboViewer.DisplayMember = “Value”;
    status_comboViewer.DropDownWidth = 400;
    status_comboViewer.TabStop = false;

    this.grid1.gridControl1.Controls.Add(status_comboViewer);
    status_comboViewer.Location = new System.Drawing.Point(-1000,-1000);

    this.grid1.gridControl1.Columns[ “Status” ].CellEditor = status_comboEditor;
    this.grid1.gridControl1.Columns[ “Status” ].CellViewer = new ControlViewer( status_comboViewer, “SelectedValue” );

    Imported from legacy forums. Posted by C# (had 400 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks!

    Imported from legacy forums. Posted by csperler (had 4079 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.