コード例 #1
0
        /// <summary>
        ///    <para>Prepares a cell for editing.</para>
        /// </summary>
        protected internal override void Edit(CurrencyManager source,
                                              int rowNum,
                                              Rectangle bounds,
                                              bool readOnly,
                                              string displayText,
                                              bool cellIsVisible)
        {
            DebugOut("Begining Edit, rowNum :" + rowNum.ToString(CultureInfo.InvariantCulture));

            Rectangle originalBounds = bounds;

            edit.ReadOnly = readOnly || ReadOnly || DataGridTableStyle.ReadOnly;

            edit.Text = GetText(GetColumnValueAtRow(source, rowNum));
            if (!edit.ReadOnly && displayText != null)
            {
                // tell the grid that we are changing stuff
                DataGridTableStyle.DataGrid.ColumnStartedEditing(bounds);
                // tell the edit control that the user changed it
                edit.IsInEditOrNavigateMode = false;
                edit.Text = displayText;
            }

            if (cellIsVisible)
            {
                bounds.Offset(xMargin, 2 * yMargin);
                bounds.Width  -= xMargin;
                bounds.Height -= 2 * yMargin;
                DebugOut("edit bounds: " + bounds.ToString());
                edit.Bounds = bounds;

                edit.Visible = true;

                edit.TextAlign = Alignment;
            }
            else
            {
                edit.Bounds = Rectangle.Empty;
                // edit.Bounds = originalBounds;
                // edit.Visible = false;
            }

            edit.RightToLeft = DataGridTableStyle.DataGrid.RightToLeft;

            edit.Focus();

            editRow = rowNum;

            if (!edit.ReadOnly)
            {
                oldValue = edit.Text;
            }

            // select the text even if the text box is read only
            // because the navigation code in the DataGridTextBox::ProcessKeyMessage
            // uses the SelectedText property
            if (displayText == null)
            {
                edit.SelectAll();
            }
            else
            {
                int end = edit.Text.Length;
                edit.Select(end, 0);
            }

            if (edit.Visible)
            {
                DataGridTableStyle.DataGrid.Invalidate(originalBounds);
            }
        }