DataGridView 编辑 出现 下拉框

/// <summary>
/// 选择不同的标记
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            DataGridViewCell dgvcell = (DataGridViewCell)this.comboBox1.Tag;
            if ((dgvcell != null) && (this.DgvchargeTypeList.CurrentCell == dgvcell))
            {
                if (this.comboBox1.SelectedItem != null)
                {
                    this.DgvchargeTypeList.Rows[dgvcell.RowIndex].Cells["stateName2"].Value
                        = (this.comboBox1.Text).ToString();
                }
                else
                {
                   this.DgvchargeTypeList.Rows[dgvcell.RowIndex].Cells[this.stateName2.Index].Value = "";
                }
            }
        }

        private void DgvchargeTypeList_CurrentCellChanged(object sender, EventArgs e)
        {
            DataGridViewCell dgvCell = this.DgvchargeTypeList.CurrentCell;
            if (dgvCell == null)
                return;
            if (dgvCell.ColumnIndex == 3)//this.colNum.Index---colNum是datagridview的列名

            //或者写成if(dgvcell.columnIndex=this.colNum.Index)
            {
                this.comboBox1.Items.Clear();
                MarkerDt = FTMF.MarkerBind();
                foreach (DataRow row in MarkerDt.Rows)
                {
                    this.comboBox1.Items.Add(row["stateName"]);
                }
                this.comboBox1.Size = dgvCell.Size;
                Rectangle rect = this.DgvchargeTypeList.GetCellDisplayRectangle(dgvCell.ColumnIndex, dgvCell.RowIndex, false);
                this.comboBox1.Top = rect.Top + this.DgvchargeTypeList.Top;
                this.comboBox1.Left = rect.Left + this.DgvchargeTypeList.Left;

                this.comboBox1.Text = dgvCell.Value.ToString();
                this.comboBox1.Tag = dgvCell;

                this.comboBox1.Visible = true;
            }
            else
            {
                this.comboBox1.Visible = false;
            }
        }

posted @ 2012-05-27 10:49  风与雨无阻  阅读(393)  评论(0编辑  收藏  举报