Ejemplo n.º 1
0
    public override void InitializeEditingControl(int rowIndex, object
                                                  initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
    {
        // Set the value of the editing control to the current cell value.
        base.InitializeEditingControl(rowIndex, initialFormattedValue,
                                      dataGridViewCellStyle);
        MyOptionsEditingControl ctl =
            DataGridView.EditingControl as MyOptionsEditingControl;

        if (this.Style.Font != null)
        {
            this.Style.Font = new System.Drawing.Font(this.Style.Font, System.Drawing.FontStyle.Regular);
        }
        MyOptionsColumn moc = this.DataGridView.Columns[this.DataGridView.CurrentCell.ColumnIndex] as MyOptionsColumn;
        DataTable       dt  = (DataTable)moc.DataSource;

        ctl.BindData(dt);
        if (this.Value != null)
        {
            if (ctl.Text != this.Value.ToString())
            {
                ctl.Text = this.Value.ToString();
            }
        }
        else
        {
            ctl.Text = "";
        }
    }
Ejemplo n.º 2
0
        public static void InitDataGridViewColumn(DataGridViewColumn c, System.Data.DataTable dt)
        {
            MyOptionsColumn moc = c as MyOptionsColumn;

            if (moc != null)
            {
                moc.DataSource = dt;
            }
            else
            {
                DataGridViewComboBoxColumn cbc = c as DataGridViewComboBoxColumn;
                if (cbc != null)
                {
                    cbc.DataSource    = dt;
                    cbc.DisplayMember = "Name";
                    cbc.ValueMember   = "Value";
                }
            }
        }