Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Activating current control in UserControl
Message
From
10/11/2008 00:21:17
 
 
To
03/11/2008 15:55:31
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 3.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01358315
Message ID:
01360828
Views:
32
Sorry Andrus, I've been on vacation for the past week. Looks like Viv's been helping out. =0)

>Re-activating form selects whole grid TextBox contents. How to change this that grid TextBox restores its old selection state and cursor position (not selected or part of text selected) ?

I'd say that you might want to have a subclass of the DataGridViewTextBoxColumn that keeps track of that information and re-sets it when it's activated ... just off the top of my head, but will that do it for you?

~~Bonnie






>>I haven't had time to try your code so this is just supposition. Although the drill-down in the Deactivate event may capture the right contol the Activated event won't find the reference
>>Maybe any nested ContainerControl needs to implement the same logic as the form itself (i.e store current control when focus moves away and restore focus to it when the ContainerControl itself gets focus)....
>
>Thank you very much.
>I added Grid.Focus() to code and this solves this issue.
>
>Re-activating form selects whole grid TextBox contents. How to change this that grid TextBox restores its old selection state and cursor position (not selected or part of text selected) ?
>
>Test code:
>
>
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);
>    }
>
>    protected override void OnActivated(EventArgs e)
>    {
>        base.OnActivated(e);
>        if (this.LastFocus != null)
>        {
>            grid.Focus();
>            this.LastFocus.Focus();
>        }
>    }
>
>    protected override void OnDeactivate(EventArgs e)
>    {
>        base.OnDeactivate(e);
>        this.LastFocus = this.ActiveControl;
>        while (LastFocus is IContainerControl)
>            LastFocus = ((IContainerControl)LastFocus).ActiveControl;
>    }
>}
>
>class MyUserControl : UserControl
>{
>    internal MyUserControl()
>    {
>        Height = 100;
>        Controls.Add(new TextBox());
>    }
>}
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform