DataGridView bound to DataTable. Getting comboboxes for enums

If you have a DataTable that has a column of some Enum type.

And you bind a DataGridView to this DataTable (myDgv.DataSource = myDataTable)..

How can you make the DataGridView show a combobox (or is it drop-down-list? The one where the only thing you can do is select) in each cell of for this column? The combobox should have the current value selected, and the other possible enum values selectable.

At the moment, these cells show as plain old editable text cells with the string representation of the enum value in them.


I would suggest that you read Forcing the DataGridView to do my bidding - a tale of ComboBox hackery:

At first I was optimistic about the DataGridView samples (overview)(Download The DataGridView samples), but I didn't see anything that did what I wanted to do: take an enum value and represent it in the grid with a combobox. So, here's how I did it.

Also you should check out How to: Bind Objects to Windows Forms DataGridView Controls:

The following code example demonstrates how to bind a collection of objects to a DataGridView control so that each object displays as a separate row. This example also illustrates how to display a property with an enumeration type in a DataGridViewComboBoxColumn so that the combo box drop-down list contains the enumeration values.

Well, I don't know if what I'm going to say fits here, but I recently had a similar requirement: display a Link in a DataGridView bound to a DataSet, this is

protected void grvResultado_RowDataBound(object sender, GridViewRowEventArgs e) {
    if (grvResultado.HeaderRow == null || grvResultado.HeaderRow.Cells.Count == 0) return;
    bool hasLink = false;
    int ind = 0;
    foreach (TableCell c in grvResultado.HeaderRow.Cells) {
        if (c.Text == "link") {
            hasLink = true;
    if (!hasLink) return;

    if (e.Row.RowType == DataControlRowType.DataRow) {
        TableCell c = e.Row.Cells[ind];
        var lnk = new HyperLink();
        lnk.Text = "Ver";
        lnk.NavigateUrl = c.Text;

You can accustom what you need as I did

Need Your Help

Matlab: linear congruence solver that supports a non-prime modulus?

matlab cryptography linear-algebra symbolic-math mupad

I'm working on some Matlab code to perform something called the Index Calculus attack on a given cryptosystem (this involves calculating discrete log values), and I've gotten it all done except for...

iterate through the fields of each object of a linked list


Below I have got a class with two int variables from which I have created a number of objects which I have stored in the linked list. Now I want to loop through each object and compare THEIR FIELDS...