Enums displaying numbers instead of text in cell

Posted by: tyndaleit on 8 September 2017, 2:39 pm EST

  • Posted 8 September 2017, 2:39 pm EST

    <p>Currently I have a datatable I've populated and changed the column type of to an enum I have defined:  </p><p>enum MyEnum{<br>  Inactive =0,<br>  Active = 1,<br>};</p><p>The data that then fills this column comes in the form of an Int32 type from a SQL database.  However, when I attach the datatable to a fpSpread.DataSource, the column displays the integer instead of the enumeration's .ToString() output.  This is in contrast to how the DataGridView changes the display text to reflect the enum text.</p><p> My question is what do I have to do to have my Sheet display the text, while holding the correct integer value?<br><br>I even tried to overwrite the value using the enum directly once populated and the number is still displayed</p><p>fswsWorkUnits.Cells[0, 1].Value = Workflows.WorkFlowStatus.Inactive;<br></p>
  • Replied 8 September 2017, 2:39 pm EST

    <P style="MARGIN:0in 0in 0pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;" class=MsoNormal><SPAN style="COLOR:#1f497d;"><FONT face=arial,helvetica,sans-serif><FONT color=#000099><FONT size=3>You could use a custom celltype that overrides the PaintCell method and changes the value being painted from the number to the ToString of the enum associated with the number. </FONT><SPAN style="FONT-FAMILY:'Times New Roman','serif';FONT-SIZE:12pt;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"><FONT size=4>Another suggestion is to use a ComboBoxCellType and set it up with the enum strings in the list, the enum values in the item data, and set EditorValue to EditorValue.ItemData</FONT></SPAN></FONT></FONT></SPAN></P>
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels