How to display enum values in datagridview column

后端 未结 5 987
臣服心动
臣服心动 2021-01-18 02:30

I have this Database, not of my design but I have to work with it, that contains a table like so :

 id  |   Name     |  status  | ...
-----+------------+-------         


        
5条回答
  •  爱一瞬间的悲伤
    2021-01-18 03:30

    You can use RowPostPaint event of DataGridView. You can do as following.

    private void TestGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
          if(e.RowIndex == -1) return;
            TestGridView[YourColumnIndex, e.RowIndex].Value = YourEnumValue; // You can get your enum string value here.
        }
    

    In this method you need to check for the value you want to update otherwise this will throw you into infinite loop for updating the row. Once value is updated you should avoid updating it again. This solution is only applicable if this is readonly cell.

    I would suggest to go with BFree's solution, if that's not possible then you can think of this.

提交回复
热议问题