Fix DataGridView ComboBox and Button cell rendering in dark mode - #15075
Fix DataGridView ComboBox and Button cell rendering in dark mode#15075LeafShi1 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The current dark-mode rendering logic introduces correctness issues (hard-coded colors and state-dependent text color mismatches) that should be addressed before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Improves WinForms DataGridView dark-mode theming by adjusting how ComboBox and Button cells choose colors/renderers so text remains readable and button cells visually match standard dark-mode buttons.
Changes:
- Update
DataGridViewComboBoxCellrendering to use dark-mode-compatible text/drop-down button visuals. - Update
DataGridViewButtonCellrendering to reuse existing WinForms dark-mode button renderers and surfaceEffectiveVisualStylesModeinternally for renderer selection. - Add unit tests for the new internal helper logic.
File summaries
| File | Description |
|---|---|
| src/test/unit/System.Windows.Forms/System/Windows/Forms/DataGridViewComboBoxCellTests.cs | Adds a unit test covering ComboBox cell text color selection under dark-mode conditions. |
| src/test/unit/System.Windows.Forms/System/Windows/Forms/DataGridViewButtonCellTests.cs | Adds a unit test for Button cell style color selection helper. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewComboBoxCell.DataGridViewComboBoxCellRenderer.cs | Adjusts ComboBox drop-down button rendering behavior for dark mode. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewComboBoxCell.cs | Refactors ComboBox text color selection into a helper with dark-mode branching. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewButtonCell.DataGridViewButtonCellRenderer.cs | Introduces dark-mode button renderers and returns content bounds + text color from the draw routine. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewButtonCell.cs | Integrates dark-mode renderer usage into Button cell painting and extracts style color selection helper. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridView.cs | Exposes an internal accessor for effective visual styles mode for internal consumers. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15075 +/- ##
=============================================
Coverage 37.24166% 37.24166%
=============================================
Files 246 246
Lines 9774 9774
Branches 1029 1029
=============================================
Hits 3640 3640
Misses 5970 5970
Partials 164 164
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
The dark-mode ComboBox drop-down button rendering path appears to ignore RTL handling, which risks a functional rendering regression for right-to-left DataGridViews.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 2
- Review effort level: Lite
Fixes #15077
Root Cause
DataGridViewComboBoxCell continued using visual-style colors that could return dark text on a dark background.
DataGridViewButtonCell used the legacy visual-style renderer instead of the dark-mode renderers used by regular WinForms buttons.
Proposed changes
Customer Impact
Regression?
Risk
Screenshots
Before
ComboBox cell text could be unreadable against a dark background.
DataGridView Button cells did not visually match regular WinForms buttons in dark mode.
After
ComboBox text is readable in both selected and unselected dark-mode cells.
DataGridView Button cells use the same dark-mode rendering as regular WinForms buttons.
AfterChanges.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow