Exemple #1
0
 /// <summary>
 /// Tell the world when a cell is about to finish being edited.
 /// </summary>
 protected virtual void OnCellEditFinishing(CellEditEventArgs e)
 {
     if (this.CellEditFinishing != null)
     {
         this.CellEditFinishing(this, e);
     }
 }
Exemple #2
0
        /// <summary>
        /// Tell the world when a cell is about to finish being edited.
        /// </summary>
        protected virtual void OnCellEditorValidating(CellEditEventArgs e)
        {
            // Hack. ListView is an imperfect control container. It does not manage validation
            // perfectly. If the ListView is part of a TabControl, and the cell editor loses
            // focus by the user clicking on another tab, the TabControl processes the click
            // and switches tabs, even if this Validating event cancels. This results in the
            // strange situation where the cell editor is active, but isn't visible. When the
            // user switches back to the tab with the ListView, composite controls like spin
            // controls, DateTimePicker and ComboBoxes do not work properly. Specifically,
            // keyboard input still works fine, but the controls do not respond to mouse
            // input. SO, if the validation fails, we have to specifically give focus back to
            // the cell editor. (this is the Select() call in the code below).
            // But (there is always a 'but'), doing that changes the focus so the cell editor
            // triggers another Validating event -- which fails again. From the user's point
            // of view, they click away from the cell editor, and the validating code
            // complains twice. So we only trigger a Validating event if more than 0.1 seconds
            // has elapsed since the last validate event.
            // I know it's a hack. I'm very open to hear a neater solution.

            // Also, this timed response stops us from sending a series of validation events
            // if the user clicks and holds on the OLV scroll bar.
            if ((Environment.TickCount - lastValidatingEvent) < 500)
            {
                e.Cancel = true;
            }
            else
            {
                lastValidatingEvent = Environment.TickCount;
                if (this.CellEditValidating != null)
                {
                    this.CellEditValidating(this, e);
                }
            }
            lastValidatingEvent = Environment.TickCount;
        }