473,811 Members | 2,717 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ad d(new DataGridViewTex tBoxColumn());
grid.EditMode = DataGridViewEdi tMode.EditOnEnt er;
Controls.Add(gr id);
}
}

Oct 31 '08 #1
5 4071
"Andrus" <ko********@hot .eewrote in message
news:ex******** ******@TK2MSFTN GP02.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(ob ject sender, EventArgs e) {
MyDataGridViewC ontrol.Focus();
}

private void MyForm_Load(obj ect sender, EventArgs e) {
MyDataGridViewC ontrol.Focus();
}

Cheers,
BH

"Andrus" <ko********@hot .eewrote in message
news:uo******** ******@TK2MSFTN GP05.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.Collecti ons.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.Ad d(new DataGridViewTex tBoxColumn());
grid.EditMode = DataGridViewEdi tMode.EditOnEnt er;
Controls.Add(gr id);
}
protected override void OnClick(System. EventArgs e)
{
base.OnClick(e) ;
grid.Focus();
}

protected override void OnLoad(System.E ventArgs 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.Collecti ons.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()
{
ToolStripContai ner tc = new ToolStripContai ner();

grid = new DataGridView();
grid.Columns.Ad d(new DataGridViewTex tBoxColumn());
grid.EditMode = DataGridViewEdi tMode.EditOnEnt er;
grid.Top = 120;
grid.Height = 300;
Controls.Add(tc );
tc.ContentPanel .Controls.Add(n ew MyUserControl() );

tc.ContentPanel .Controls.Add(g rid);
this.Activated += new EventHandler(Ch ildform_Activat ed);
this.Deactivate += new EventHandler(Ch ildform_Deactiv ate);
}

void Childform_Activ ated(object sender, EventArgs e)
{
if (this.LastFocus != null)
this.LastFocus. Focus();
}

void Childform_Deact ivate(object sender, EventArgs e)
{
this.LastFocus = this.ActiveCont rol;
}
}

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

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

Similar topics

4
10087
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 combobox, open up another datagridview instead of the combobox dropdownlist. The reason I want to do this, is so I can show more than one column at a time in the drop down list. Instead of trying to make a multi-column combo, I thought it would be much...
1
4716
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 have changed to 40tude and can't see it in the newly dowloaded messages. It was originally html (tut tut) so maybe it didn't register. I have tried a new xml file and generated a new xsd file from it using xsd.exe and now the xml file produces...
0
9101
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 : http://img89.imageshack.us/img89/1251/dbschemaep9.jpg What happens is : 1. Form loads with values from database inside the DGV 2. I press the checkbox to enable editing/adding etc in the grid (see code event)
0
1309
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 : http://img89.imageshack.us/img89/1251/dbschemaep9.jpg What happens is : 1. Form loads with values from database inside the DGV 2. I press the checkbox to enable editing/adding etc in the grid (see code event)
7
15667
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 there an equivalent property for the DataGridView? I have searched, but have not found one. I would like the user to be able to see all the columns of the table on one screen - thus eliminating the need to use the horizontal scroll bar to view...
3
7122
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 error is: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index This error has to do with one line in particular. Me.Inventory_TransactionsDataGridView.Rows(e.RowIndex).Cells(0).Value =
0
2065
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
1495
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 changes made by this checkbox column. But the state of last checkbox is always not saved, unless I click somewhere else on the form. //all of these line code does not help!!!!
0
897
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
9727
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10398
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.