让datagridview 出现 下拉框

本文探讨了在特定场景下如何根据不同的标记进行事件响应,包括参数解析、数据更新及界面交互的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/// <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;
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值