question

MRUTYUNJAYAMAHAPATRA-6389 avatar image
0 Votes"
MRUTYUNJAYAMAHAPATRA-6389 asked DanielZhang-MSFT commented

DataGridTableStyle, DataGridColumnStyle in .Net 5

Hi, We are migrating our project to .Net 5
DataGridTableStyle, DataGridColumnStyle is deprecated in >Net 5 .Can anybody please tell me that what is the corresponding of that .Net 5

dotnet-csharpwindows-wpfwindows-formsdotnet-runtimewindows-platform-network
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

vb2ae avatar image
0 Votes"
vb2ae answered

I would switch to using a DataGridView from the DataGrid

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered DanielZhang-MSFT edited

Hi MRUTYUNJAYAMAHAPATRA-6389,
As document said that starting with .NET Core 3.1, various Windows Forms controls are no longer available, such as DataGrid.
And associated APIs (DataGridTableStyle, DataGridColumnStyle, DataGridLineStyle...)that are removed.
The recommended replacement is DataGridView, you can see all the properties and methods it currently supports in this document.
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered DanielZhang-MSFT commented

Hello,

Best to use a DataGridView, format cells using CellFormating event. Although a DataGrid has been around for a long time, since the DataGridView arrived this is the recommended way to work with data. Upside, you have more control over styling, downside, styling requires more effort on the part of a developer.

The following Microsoft Word document should be more than enough to help with formatting and more.

Resources for formatting

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for your reply . May I know how can I implement Table Style..

It is implemented as below. which is not working in .Net 5. How can I migrate code below to .Net 5

             private void setupTableStyle()
     {
         DataGridTableStyle tableStyle = new DataGridTableStyle();
         tableStyle.MappingName = "DataFilesTable";
         tableStyle.ColumnHeadersVisible = true;
         tableStyle.RowHeadersVisible = false;

         DataGridColumnStyle colStyle = new DataGridComboBoxColumn( 100, null );
         colStyle.MappingName = "Disk Drive";
         colStyle.HeaderText = "Disk Drive";
         colStyle.Width = 83;
         ((DataGridComboBoxColumn)colStyle).ComboBox.DataSource = diskDrivesView;
         ((DataGridComboBoxColumn)colStyle).ComboBox.DisplayMember = identifier.ColumnName;
         ((DataGridComboBoxColumn)colStyle).ComboBox.ValueMember = driveAlias.ColumnName;
         tableStyle.GridColumnStyles.Add( colStyle );


                                                   
         dataFilesGrid.TableStyles.Add( tableStyle );
0 Votes 0 ·
DanielZhang-MSFT avatar image DanielZhang-MSFT MRUTYUNJAYAMAHAPATRA-6389 ·

Hi @MRUTYUNJAYAMAHAPATRA-6389,
First, you need to know that neither DataGridTableStyle or DataGridColumnStyle is applicable to .Net 5.
As we said before, the recommended replacement is DataGridView in .Net 5.
And the DataGridView control provides a customizable table for displaying data.
The DataGridView class allows customization of cells, rows, columns, and borders through the use of properties such as DefaultCellStyle, ColumnHeadersDefaultCellStyle, CellBorderStyle, and GridColor.
For more information, see Basic Formatting and Styling in the Windows Forms DataGridView Control.
Best Regards,
Daniel Zhang


0 Votes 0 ·