I've got a DataGrid completely in code-behind as the whole GUI is dynamically generated.
I have stumbled upon a problem whereby the headers in my dataGrid do not display underscores. I have thus read that wrapping the headers in TextBlocks will solve this problem.
However, my DataGrid's source is a DataTable, and I am not sure how to go about wrapping the headers of the columns in a TextBlock since everything is auto-generated.
This is my code:
DataGrid dgResults = new DataGrid();
dgResults.IsReadOnly = true;
dgResults.AutoGenerateColumns = true;
dgResults.CanUserAddRows = false;
dgResults.CanUserDeleteRows = false;
dgResults.CanUserReorderColumns = false;
dgResults.CanUserResizeColumns = false;
dgResults.CanUserResizeRows = false;
dgResults.CanUserSortColumns = false;
dgResults.ItemsSource = dtResults.AsDataView();
If anyone has a similar problem, I've solved it myself. This can be handled in the DataGrid's OnColumnGenerating event.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.