Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DataGridview column does not receive focus on form activation

DataGridview column does not receive focus on form activation

Scheduled Pinned Locked Moved C#
csshelptutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrusM
    wrote on last edited by
    #1

    To reproduce: 1. Run code. 2. Enter some data to grid 3. Click other form caption 4. Click original form caption 5. Enter some characters Observed: entered characters are ignored Expected: entered characters must appear in last active textbox How to fix ? Andrus. using System.Windows.Forms; using System.Collections.Generic; using System; public class Test { static void Main() { Application.Run(new MainForm()); } } class MainForm : Form { public MainForm() { WindowState = FormWindowState.Maximized; IsMdiContainer = true; Form frm = new Childform(); frm.MdiParent = this; frm.Show(); Form frm2 = new Childform(); frm2.MdiParent = this; frm2.Show(); frm2.Left = 2000; } } class Childform : Form { DataGridView grid; Control LastFocus = null; public Childform() { ToolStripContainer tc = new ToolStripContainer(); grid = new DataGridView(); grid.Columns.Add(new DataGridViewTextBoxColumn()); grid.EditMode = DataGridViewEditMode.EditOnEnter; grid.Top = 120; grid.Height = 300; Controls.Add(tc); tc.ContentPanel.Controls.Add(new MyUserControl()); tc.ContentPanel.Controls.Add(grid); this.Activated += new EventHandler(Childform_Activated); this.Deactivate += new EventHandler(Childform_Deactivate); } void Childform_Activated(object sender, EventArgs e) { if (this.LastFocus != null) this.LastFocus.Focus(); } void Childform_Deactivate(object sender, EventArgs e) { this.LastFocus = this.ActiveControl; while (LastFocus is IContainerControl) LastFocus = ((IContainerControl)LastFocus).ActiveControl; } } class MyUserControl : UserControl { internal MyUserControl() { Height = 100; Controls.Add(new TextBox()); } }

    Andrus

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups