Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Lookup table for DataGridView ComboBoxColumn
Message
De
06/10/2007 03:37:09
 
 
À
05/10/2007 13:12:37
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01258030
Message ID:
01259128
Vues:
13
>This seems to be a .NET bug: "Form.Show does not activate form". Should I report it?

I think they will likely tell you it is by design. What it looks like to me is you are showing the form in the middle of the focus changing. The form is shown and actually flashes up in front, but then the focus change finishes and the form is moved back. Make sense?

The way to get around it is to prevent the focus from changing, this for instance works with your example code:
public class MyComboBox : ComboBox
  {
  public MyComboBox() : base()
    {
    this.KeyUp += new KeyEventHandler(TestKey);
    }

  protected override bool IsInputKey(Keys keyData)
    {
    if (keyData==Keys.Tab)
      {
      return true;
      }
    return base.IsInputKey(keyData);
    }

  public void TestKey(object sender, KeyEventArgs e)
    {
    if (e.KeyCode == Keys.Tab)
      {
      Form f = new Form();
      f.Text = "Modeless lookup form";
      f.Show();
      }
    }
  }
John

>Bonnie,
>
>I havent found any solution.
>If combobox is placed directly to Form, lookup form is activated.
>If combobox is in DataGridView, lookup form is not activated.
>My existing VFP application uses modeless lookup forms and users like it: you can open into other forms, activate other lookup forms from lookup form.
>Selection event sends message to the form which calls lookup form.
>Modeless lookup are extremely convenient so I'm looking for a way to implement this in .NET 2
>
>This seems to be a .NET bug: "Form.Show does not activate form".
>Should I report it?
>
>Any idea how to activate modeless form from combobox or textbox validation event ?
>
>>Have you got this figured out yet? I played around with it for about an hour this morning and couldn't come up with anything. I thought maybe the ProcessCmdKey method might have something to do with it, but I still couldn't make it work. Too bad your Form has to be modal-less because obviously a modal Form works fine.
>>
>>~~Bonnie
>>
>>
>>
>>
>>>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:
>>>
>>>1. Next row receives focus
>>>2. Current form remains active
>>>
>>>Expected:
>>>
>>>1. Focus should remain in current combobox.
>>>2. Lookup form must become active form.
>>>
>>>How to fix ?
>>>
>>>Andrus.
>>>
>>>
>>>
>>>using System;
>>>using System.Windows.Forms;
>>>
>>>class ComboBoxColumn : DataGridViewComboBoxColumn {
>>>}
>>>
>>>class ComboBoxCell : DataGridViewComboBoxCell {
>>>
>>>public override Type EditType {
>>>
>>>get {
>>>return typeof(ComboBoxEditingControl);
>>>}
>>>}
>>>
>>>}
>>>
>>>class ComboBoxEditingControl : MyComboBox, IDataGridViewEditingControl {
>>>
>>>protected int rowIndex;
>>>protected DataGridView dataGridView;
>>>protected bool valueChanged = false;
>>>
>>>protected override void OnTextChanged(EventArgs e) {
>>>
>>>base.OnTextChanged(e);
>>>NotifyDataGridViewOfValueChange();
>>>}
>>>
>>>protected virtual void NotifyDataGridViewOfValueChange() {
>>>this.valueChanged = true;
>>>
>>>if (this.dataGridView != null) {
>>>this.dataGridView.NotifyCurrentCellDirty(true);
>>>}
>>>
>>>}
>>>
>>>public Cursor EditingPanelCursor {
>>>
>>>get {
>>>return Cursors.IBeam;
>>>}
>>>
>>>}
>>>
>>>public DataGridView EditingControlDataGridView {
>>>get {
>>>return this.dataGridView;
>>>}
>>>
>>>set {
>>>this.dataGridView = value;
>>>}
>>>}
>>>
>>>public object EditingControlFormattedValue {
>>>
>>>set {
>>>
>>>if (value.ToString() != this.Text) {
>>>
>>>this.Text = value.ToString();
>>>
>>>NotifyDataGridViewOfValueChange();
>>>
>>>}
>>>
>>>}
>>>
>>>get {
>>>
>>>return this.Text;
>>>
>>>}
>>>
>>>}
>>>
>>>public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts
>>>context) {
>>>
>>>return this.Text;
>>>
>>>}
>>>
>>>
>>>
>>>public void PrepareEditingControlForEdit(bool selectAll) {
>>>
>>>}
>>>
>>>public bool RepositionEditingControlOnValueChange {
>>>
>>>get {
>>>return false;
>>>}
>>>}
>>>
>>>public int EditingControlRowIndex {
>>>
>>>get {
>>>return rowIndex;
>>>}
>>>
>>>set {
>>>this.rowIndex = value;
>>>}
>>>}
>>>
>>>public void ApplyCellStyleToEditingControl(DataGridViewCellStyle
>>>dataGridViewCellStyle) {
>>>DropDownStyle = ComboBoxStyle.DropDown;
>>>}
>>>
>>>public bool EditingControlWantsInputKey(Keys keyData, bool
>>>dataGridViewWantsInputKey) {
>>>return !dataGridViewWantsInputKey;
>>>}
>>>
>>>public bool EditingControlValueChanged {
>>>
>>>get {
>>>return valueChanged;
>>>}
>>>
>>>set {
>>>valueChanged = value;
>>>}
>>>}
>>>
>>>
>>>
>>>public class Form1 : Form {
>>>
>>>private DataGridView dataGridView1 = new myDataGridView();
>>>
>>>[STAThread]
>>>public static void Main() {
>>>try {
>>>Application.Run(new Form1());
>>>}
>>>catch (Exception e) {
>>>MessageBox.Show(e.ToString());
>>>}
>>>}
>>>
>>>public Form1() {
>>>this.Controls.Add(this.dataGridView1);
>>>this.Load += new EventHandler(Form1_Load);
>>>}
>>>
>>>private void Form1_Load(object sender, EventArgs e) {
>>>
>>>ComboBoxColumn comboBoxColumn = new ComboBoxColumn();
>>>ComboBoxCell ComboBoxCell = new ComboBoxCell();
>>>comboBoxColumn.CellTemplate = ComboBoxCell;
>>>dataGridView1.Columns.Add(comboBoxColumn);
>>>}
>>>}
>>>}
>>>
>>>public class MyComboBox : ComboBox {
>>>
>>>protected override void OnValidating(System.ComponentModel.CancelEventArgs
>>>e) {
>>>
>>>e.Cancel = true;
>>>base.OnValidating(e);
>>>Form f = new Form();
>>>f.Text = "Modeless lookup form";
>>>f.Show();
>>>}
>>>}
>>>
>>>public class myDataGridView : DataGridView {
>>>
>>>protected override void OnDataError(bool displayErrorDialogIfNoHandler,
>>>DataGridViewDataErrorEventArgs e) {
>>>e.Cancel = false;
>>>}
>>>}
>>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform