Esempio n. 1
0
 private void TextUnionCombox_CellEndEditFunc(DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0)
     {
         if (this.Columns[e.ColumnIndex] is DataGridViewTextBoxColumn_UnionCombox)
         {
             if (this.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewComboBoxCell)
             {
                 try
                 {
                     DataGridViewTextBoxColumn_UnionCombox NowTCColumn = this.Columns[e.ColumnIndex] as DataGridViewTextBoxColumn_UnionCombox;
                     DataGridViewTextBoxCell  cell    = new DataGridViewTextBoxCell();
                     DataGridViewComboBoxCell ComCell = this.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewComboBoxCell;
                     if ((ComCell != null) && (ComCell.Value != null))
                     {
                         cell.Value = new ListItem(NowTCColumn.ComboxItems[ComCell.Value.ToString()], ComCell.Value.ToString());
                     }
                     else
                     {
                         cell.Value = NowTCColumn.OldItem;
                     }
                     this.Rows[e.RowIndex].Cells[e.ColumnIndex] = cell;
                     this.EndEdit();
                     this.ReadOnly = true;
                 }
                 catch (Exception exception)
                 {
                     throw exception;
                 }
             }
         }
     }
 }
Esempio n. 2
0
        protected override void OnCellDoubleClick(DataGridViewCellEventArgs e)
        {
            base.OnCellDoubleClick(e);

            if (e.RowIndex >= 0)
            {
                if (this.Columns[e.ColumnIndex] is DataGridViewTextBoxColumn_UnionCombox)
                {
                    if (this.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewTextBoxCell)
                    {
                        try
                        {
                            DataGridViewTextBoxColumn_UnionCombox NowTCColumn = this.Columns[e.ColumnIndex] as DataGridViewTextBoxColumn_UnionCombox;
                            NowTCColumn.EditeCellEvent = e;
                            NowTCColumn.EndEditCell    = false;
                            this.Timer_TC_Edit.Start();
                            DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
                            cell.DisplayMember = "Text";
                            cell.ValueMember   = "Value";
                            DataGridViewTextBoxCell TextCell = this.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewTextBoxCell;
                            NowTCColumn.OldItem = (TextCell != null) ? ((TextCell.Value is ListItem) ? TextCell.Value as ListItem : null) : null;
                            foreach (string key in NowTCColumn.ComboxItems.Keys)
                            {
                                ListItem item = new ListItem(NowTCColumn.ComboxItems[key], key);
                                cell.Items.Add(item);
                            }
                            cell.Value = (TextCell != null) ? ((TextCell.Value is ListItem) ? (TextCell.Value as ListItem).Value : null) : null;
                            this.Rows[e.RowIndex].Cells[e.ColumnIndex] = cell;
                            this.ReadOnly = false;
                            this.BeginEdit(true);
                        }
                        catch (Exception exception)
                        {
                            throw exception;
                        }
                    }
                }
            }
        }