473,421 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

DataGridview column does not receive focus on form activation

Steps to reproduce issue:

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 textbox which was last active

How to fix ?

Andrus.

using System.Windows.Forms;

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
{
public Childform()
{
var grid = new DataGridView();
grid.Columns.Add(new DataGridViewTextBoxColumn());
grid.EditMode = DataGridViewEditMode.EditOnEnter;
Controls.Add(grid);
}
}

Oct 31 '08 #1
5 4043
"Andrus" <ko********@hot.eewrote in message
news:ex**************@TK2MSFTNGP02.phx.gbl...
Steps to reproduce issue:

1. Run code.
2. Enter some data to grid
3. Click other form caption
4. Click original form caption
Are you clicking on some part of the form that isn't the dgv? What happens
if you click directly on the control if so?
Oct 31 '08 #2
Are you clicking on some part of the form that isn't the dgv? What happens
if you click directly on the control if so?
Clicking in control activates this control.
I need activation when form is simply activated, when modeless lookup form
is called during data enty.

Andrus.

Nov 1 '08 #3
Try to set the focus to your dgv wherever you need to, something like this:

private void MyForm_Click(object sender, EventArgs e) {
MyDataGridViewControl.Focus();
}

private void MyForm_Load(object sender, EventArgs e) {
MyDataGridViewControl.Focus();
}

Cheers,
BH

"Andrus" <ko********@hot.eewrote in message
news:uo**************@TK2MSFTNGP05.phx.gbl...
>Are you clicking on some part of the form that isn't the dgv? What
happens if you click directly on the control if so?

Clicking in control activates this control.
I need activation when form is simply activated, when modeless lookup form
is called during data enty.

Andrus.

Nov 1 '08 #4
Berryl,
Try to set the focus to your dgv wherever you need to, something like
this:
Thank you. I tried code below but problem persists.
Probably we need to activate specific textbox in some special way, maybe
remember and set cell coordinates directly?

Andrus.

using System.Windows.Forms;
using System.Collections.Generic;

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;

public Childform()
{
grid = new DataGridView();
grid.Columns.Add(new DataGridViewTextBoxColumn());
grid.EditMode = DataGridViewEditMode.EditOnEnter;
Controls.Add(grid);
}
protected override void OnClick(System.EventArgs e)
{
base.OnClick(e);
grid.Focus();
}

protected override void OnLoad(System.EventArgs e)
{
base.OnLoad(e);
grid.Focus();
}
}

Nov 1 '08 #5
Steps to reproduce issue:

Here is more advanced sample.
Last TextBox in grid is *not* activated when form is activated.

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;
}
}

class MyUserControl : UserControl
{
internal MyUserControl()
{
Height = 100;
Controls.Add(new TextBox());
}
}
Nov 2 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Aaron Smith | last post by:
Ok, this is an odd one, but I could use some assistance with the framework 2 in VB.Net... I want to have a DataGridViewColumn, only have it use the ComboBox, then when they drop down the...
1
by: mark carew | last post by:
Hi, Problem - An extra column to the left (even with row headers disabled) ---------------------------------------------------------- Apologies if this posting is already in the newsgroup; but...
0
by: Asif Mohammed | last post by:
Hello, I have a datagridview bound to a database table with 2 columns. One is an ID column "NameID" which is hidden, the other is called "Name". The schema picture is here :...
0
by: Asif Mohammed | last post by:
Hello, I have a datagridview bound to a database table with 2 columns. One is an ID column "NameID" which is hidden, the other is called "Name". The schema picture is here :...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
3
by: Tony K | last post by:
When calling my form from within my MDI, I receive this error message. InvalidOperationException was unhandled An error occurred creating the form. See Exception.InnerException for details. The...
0
by: Andrus | last post by:
I tried to use modeless picklist for DataGridView custom ComboBoxColumn without success. Steps to reproduce issue: 1. Run code 2. Enter some character 3. Press Tab Observed:
0
by: Ryan Liu | last post by:
I found DataGridView in .NET 2.0 has a bug, or maybe I used it in a wrong way, just try to confirm with you guys: I have a checkbox column in it, and a save button on the form try to save...
0
by: rk4088 | last post by:
Hi all, I'm a new to vb.net. I'm having datagridview in my windows form. I've to make a focus in the fourth column of the datagridview.. I need coding for this.. Pls help.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.