Skip to content

DataGridView select first column header cell if SelectionMode = DataGridViewSelectionMode.FullRowSelect #14649

Description

@altbodhi

.NET 10

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net10.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

  <ItemGroup>
    <Import Include="System.Data" />
    <Import Include="System.Drawing" />
    <Import Include="System.Windows.Forms" />
  </ItemGroup>
  
  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>
</Project>
open System.Windows.Forms

type App() as x =
    class
        inherit ApplicationContext()

        do
            x.MainForm <- new Form(Text = "App v1", Width = 300, Height = 200)

            let dg = new DataGridView(SelectionMode = DataGridViewSelectionMode.FullRowSelect)

            x.MainForm.Controls.Add dg
            dg.Dock <- DockStyle.Fill

            let addCol name =
                dg.Columns.Add(new DataGridViewColumn(HeaderText = name, CellTemplate = new DataGridViewTextBoxCell()))
                |> ignore

            addCol "Id"
            addCol "Name"

            dg.Rows.Add([| box 1; box "Alice" |]) |> ignore
            dg.Rows.Add([| box 2; box "Bob" |]) |> ignore
            dg.Rows.Add([| box 3; box "Rob" |]) |> ignore

        static member Run() = Application.Run(new App())
    end

App.Run()
Image

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

no

Issue description

With free or object source and SelectionMode = DataGridViewSelectionMode.FullRowSelect first column header cell
selected at startup.
I did not check but found example worked without issue if source DataTable.

Steps to reproduce

Make WinForms App
Add DataGridView with one or more columns
add object datasource or fill rows by hands and test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions