I need an editable combo (DropDownCombo style) appears on a DataGridView current cell.
I tryed setting the column type as 'DataGridViewComboBoxColumn'. It works fine but I can't
edit ComboBoxItems.
How can I edit and insert new items direcly from combo ? Is it possible ?
There is any workaround to do ?
Thanks.
Brainjar.
Loading
vitoPosted Jun 15, 2006, 7:28 AM
.....
this.cboDescrizione.Leave += new System.EventHandler(this.cboDescrizioneLeave);
.....
this.grdWPreventivo.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler( this.GrdWPreventivoCellContentClick);
this.grdWPreventivo.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler( this.GrdWPreventivoCellContentClick);
.....
.....
private void GrdWPreventivoCellContentClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
{
DataGridView grd = this.grdWPreventivo;
Rectangle rect = grd.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
if (e.ColumnIndex==0) {
RigaCorrente = e.RowIndex;
blEditing = true;
// -------------------------------------
// Set combo absolute position
// -------------------------------------
cboDescrizione.Left = rect.X + grd.Left;
cboDescrizione.Top = rect.Y + grd.Top;
cboDescrizione.BringToFront();
} else
blEditing = false;
// ---------------------------------------
// Set combo visible, so can receive focus
// ---------------------------------------
cboDescrizione.Visible = blEditing;
// -----------------------------------------
// Can combo receive Focus() ?
// -----------------------------------------
if (blEditing) cboDescrizione.Focus();
}
private void cboDescrizioneLeave(object sender, System.EventArgs e)
{
// -----------------------------------
// Stop editing. Start CellValidating.
// -----------------------------------
string valore = cboDescrizione.Text;
blEditing = false;
this.grdWPreventivo.Rows[RigaCorrente].Cells[0].Value = valore;
cboDescrizione.SendToBack();
cboDescrizione.Visible = false ;
int i = this.cboDescrizione.FindString(cboDescrizione.Text );
if (i==-1) cboDescrizione.Items.Add(cboDescrizione.Text);
}
Bye.