DataGrid exception on U+200D in text w/ Arial Unicode MS font

DataGrid exception on U+200D in text w/ Arial Unicode MS font

Post by Pete Dembr » Fri, 18 Jun 2004 15:36:11


The DataGrid control throws the following exception:

"An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in
system.windows.forms.dll. Add'l information: "A generic error occurred in
GDI+"

This occurs when I have the 'Font' property set to the "Arial Unicode MS"
font AND send it a string of Unicode-encoded text that contains the Zero
Width Non Joiner character (U+200D). The following code pasted below the
"InitializeComponent" call in a Form ctor will show the problem (of a
default-C# Windows Application project in VS.Net 2003, where the Form has a
DataGrid control named dataGrid1):

+-----------------cut here -----------------+
const string strColumn = "Column name";
DataTable myTable = new DataTable("myTable");
myTable.Columns.Add(new DataColumn(strColumn,typeof(string)));
DataRow rowNew = myTable.NewRow();
myTable.Rows.Add(rowNew);
dataGrid1.DataSource = myTable;

// PROBLEM STATEMENTs begin
rowNew[strColumn] = "\x0938\x091A\x094d\x200d\x091A";
dataGrid1.Font = new Font("Arial Unicode MS", 12);
// PROBLEM STATEMENTs end
+-----------------cut here -----------------+

If you either a) remove the "\x200d" portion of the string or b) comment out
the change of Font property (i.e. so it remains the default "Microsoft Sans
Serif" font), then it works fine.

Any ideas on a fix (besides using a different font?)