Skip to content

Fix DataGridView ComboBox and Button cell rendering in dark mode - #15075

Open
LeafShi1 wants to merge 3 commits into
dotnet:mainfrom
LeafShi1:Fix_DataGridView_dark_work_in_ComboBox
Open

Fix DataGridView ComboBox and Button cell rendering in dark mode#15075
LeafShi1 wants to merge 3 commits into
dotnet:mainfrom
LeafShi1:Fix_DataGridView_dark_work_in_ComboBox

Conversation

@LeafShi1

@LeafShi1 LeafShi1 commented Sep 10, 2026

Copy link
Copy Markdown
Member

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

  • Render DataGridView ComboBox text, border, and drop-down button using dark-compatible colors.
  • Reuse the existing WinForms dark-mode Button renderers for DataGridView Button cells.

Customer Impact

  • Customers using dark-mode DataGridViews receive readable ComboBox content and consistent Button rendering, with clearer mouse and keyboard interaction feedback.

Regression?

  • No

Risk

  • minimal

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.

BeforeChanges

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

  • Manual test and unit test

Test environment(s)

  • .net 11.0.0-beta.26458.117
Microsoft Reviewers: Open in CodeFlow

@LeafShi1
LeafShi1 requested a review from a team as a code owner September 10, 2026 08:06
@LeafShi1
LeafShi1 requested a lite review from Copilot and removed request for a team September 10, 2026 08:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 DataGridViewComboBoxCell rendering to use dark-mode-compatible text/drop-down button visuals.
  • Update DataGridViewButtonCell rendering to reuse existing WinForms dark-mode button renderers and surface EffectiveVisualStylesMode internally 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

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.24166%. Comparing base (8efd9a9) to head (819543a).

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           
Flag Coverage Δ
Debug 37.24166% <ø> (ø)
production 39.36526% <ø> (ø)
test 20.64923% <ø> (ø)
unit 39.36526% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants