Click here to Skip to main content
15,887,329 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
I have datagridview when display data on datagridview i get error
The "Format String can be only "G", "g", "X", "x", "F", "f", "D" or "d"."

i debug after that get stacktrace that show more details about error as following :

at System.Enum.ToString(String format)
  at System.Enum.ToString(String format, IFormatProvider provider)
  at System.Windows.Forms.Formatter.FormatObjectInternal(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue)
  at System.Windows.Forms.Formatter.FormatObject(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue, Object dataSourceNullValue)
  at System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle& cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)


How to solve this error please ?

What I have tried:

The "Format String can be only "G", "g", "X", "x", "F", "f", "D" or "d"."
Posted
Updated 26-Aug-19 20:04pm
v2
Comments
Patrice T 26-Aug-19 23:13pm    
And you plan to show related code?
After 175+ questions, you should have learned.

1 solution

At a guess - and a help vampire like yourself should know by now that without the relevant code that is all it can be - you are trying to set a format string on a enum field. When you do that, you can only use the formats it lists in the error message: Enum.ToString Method (System) | Microsoft Docs[^]

But then, if you had googled the error message for yourself, you would have found that link at the top of the list, just like I did ...

177 questions, and you still can't do a basic Google for yourself ... :sigh:
 
Share this answer
 
Comments
Maciej Los 27-Aug-19 2:04am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900