winforms icon indicating copy to clipboard operation
winforms copied to clipboard

The code generated by the DataGridView control has extra code for the RowTemplate.Height property

Open Tanya-Solyanik opened this issue 5 years ago • 8 comments

  • .NET Core Version: 3.1+

  • Have you experienced this same bug with .NET Framework?: No

Problem description:

The generating code for dataGirdView1 has extra code for the RowTemplate.Height property. For the newly created control at 100% scaling, designer should generate the same value as is defined by the DefaultValueAttribute

image

Expected behavior: RowTemplate.Height line should not be generated

image

Minimal repro:

  1. Create a Winforms .Net Core application.
  2. Add a DataGridView to from designer.
  3. Double click to open Form1.Designer.cs file in Solution Explorer.
  4. Observe the generated code of the dataGridView1.

Note from Dustin: DataGridViewRow.Height has a [DefaultValue(22)] attribute, so the code-gen above is expected if the value is 25.

Tanya-Solyanik avatar Jan 13 '21 23:01 Tanya-Solyanik

DefaultValueAttribute should be adjusted to match the new default font

Tanya-Solyanik avatar Jan 13 '21 23:01 Tanya-Solyanik

Similar to https://github.com/dotnet/winforms/issues/4463#issuecomment-768831519.

Closing due to age. We can reopen it if/when we receive customer feedback.

RussKie avatar Feb 21 '22 03:02 RussKie

@RussKie

Closing due to age. We can reopen it if/when we receive customer feedback.

You have it for a long time already.

I was hoping that when you deal with this issue, I will be able to raise that too. Instead, you closed this one :)

Current issue is more fatal then my previous. To break Font scaling in my reported issue you was needed to add some styles. But with this - when simple adding new DataGridView (not always - see below) to the form - you completely break DPI and Font scaling 😁 And even if you fix it manually, you have to do it again and again after every use of the designer...

Details:

  1. this.dataGridView1.RowTemplate.Height = 25; line not always adding to Form1.Designer.cs. You need to open properties of dataGridView1 for this.
  2. There is a complete out of sync between the real values and what the designer shows.

https://user-images.githubusercontent.com/17767561/154912798-8bc356b9-c28e-4168-bbf7-98c30ca056ba.mp4

  1. Broken DPI scale: Snipaste_2022-02-21_10-40-55

kirsan31 avatar Feb 21 '22 08:02 kirsan31

Thank you for linking the bug.

RussKie avatar Feb 22 '22 00:02 RussKie

@merriemcgaw can you please help prioritising this?

https://github.com/dotnet/winforms/issues/4463 should be considered as part of the fix.

RussKie avatar Feb 22 '22 00:02 RussKie

/cc @merriemcgaw

kirsan31 avatar Mar 10 '22 07:03 kirsan31

@RussKie / @merriemcgaw this needs broader fix for every Control/Property impacted by the default Font change. So far i see two bugs in this context but there could be more.

dreddy-work avatar Mar 10 '22 18:03 dreddy-work

We'll try to get to this in .NET 7, based on the feedback. We decided to do a deep dive into the default values and figure out what the best path foreword is.

merriemcgaw avatar Mar 11 '22 01:03 merriemcgaw

I duplicated the feedback ticket: https://developercommunity.visualstudio.com/t/Setting-DataGridViewRowHeight--22-in-P/10227470 with this issue.

John-Qiao avatar Dec 12 '22 07:12 John-Qiao

Thanks @John-Qiao @dmitrii-drobotov - is this something that can go on your team's backlog?

merriemcgaw avatar Dec 12 '22 23:12 merriemcgaw

@dmitrii-drobotov - is this something that can go on your team's backlog?

Sure, I added it to our backlog.

dmitrii-drobotov avatar Dec 13 '22 12:12 dmitrii-drobotov

Probably the best way to affect this Issue is to separate value of the Height property (in DataGridViewRow class) from the Thickness property (which in turn depends on Control.DefaultFont.Height). After that the DefaultValue attribute can be removed, new private const can be introduced as was proposed by @RussKie (with implementation of the Reset and ShouldSerialize methods).

This sets the correct intended value to the property in the property browser, and there is still the extra code.

image image

dkazennov avatar Jan 09 '23 16:01 dkazennov

@dkazennov thank you very match for doing this!

I want ask the team about related (but designer) issue - any chance this will be fixed? It's really very tiring to delete extra font instances every time after changing the form in the designer, and if you forget about it, font scaling breaks :(

kirsan31 avatar Jan 27 '23 08:01 kirsan31

I open 2 separate issue through Feedback with Extra Styles being generated for DataGridView and the format of the file alternates with every change (spaces are added and deleted) in comments and New Lines are deleted if initialized string is last before comment. Is the correct format for a comment the first or second, it seems to be inconsistent.

    '
    'Comment
   '

or

     '
    ' Comment
    '

Are there any test that compare results after each edit to look for side effects?

paul1956 avatar Jan 27 '23 08:01 paul1956

I want ask the team about related (but designer) issue

The images are gone from the vs feedback website. @kirsan31 - could you please explain repro steps? Or even better - open individual issues in this repo.

@merriemcgaw - FYI.

Tanya-Solyanik avatar Feb 06 '23 21:02 Tanya-Solyanik

The images are gone from the vs feedback website. @kirsan31 - could you please explain repro steps?

Yea they are gone :( But we have gif form one of the responses: https://user-images.githubusercontent.com/4403806/118398742-578e5b00-b69d-11eb-9181-35f1045fb1f3.gif that explain one part of the issue.

Or even better - open individual issues in this repo.

Wil do...

kirsan31 avatar Feb 06 '23 22:02 kirsan31

We have those images in the linked designer issue (https://github.com/microsoft/winforms-designer/issues/2225), I will duplicate it here as well: [pic1.png] pic1 [pic2.png] pic2 [gif1.gif] gif1 [gif2.gif] gif2

@kirsan31 - can you confirm these are the same images from the feedback post?

dmitrii-drobotov avatar Feb 07 '23 09:02 dmitrii-drobotov

@dmitrii-drobotov

@kirsan31 - can you confirm these are the same images from the feedback post?

Yes, they are 👍 Do I still need to create a new issue with them + description from original post?

kirsan31 avatar Feb 07 '23 09:02 kirsan31

@kirsan31 it would be great to have a new issue. Thanks!

dkazennov avatar Feb 07 '23 09:02 dkazennov

Or even better - open individual issues in this repo.

Done: https://github.com/dotnet/winforms/issues/8593

kirsan31 avatar Feb 08 '23 15:02 kirsan31

Verified this on .NET latest build: 8.0.100-preview.3.23152.5, issue was fixed, RowTemplate.Height line cannot be generated and DataGridViewRow.Height value is 25. The screenshot as same as above. data

p

Nora-Zhou01 avatar Mar 03 '23 03:03 Nora-Zhou01