//在绑定数据源的情况下添加一行



  //在绑定数据源的情况下添加一行 
           DataRow dr = ((DataTable)dataGridViewX1.DataSource).NewRow();
           dr["scode"] = "555";
           ((DataTable)dataGridViewX1.DataSource).Rows.Add(dr);


     选中指定行
foreach (DataGridViewRow row in dataGridViewX1.Rows)
                            {
                               row.Selected = false;
                               //MessageBox.Show(row.Cells["scode"].ToString());
                               //MessageBox.Show(row.Cells[1].Value.ToString());
                               if (Convert.ToInt32(row.Cells[1].Value.ToString()) == s_code)
                                  {
                                row.Selected = true;
                                  }
                            }

设置AdvTree节点不能拖动

this.advTree1.DragDropEnabled = false;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,在 `DataGridView` 控件中添加一个列,可以命名为 `操作`,然后设置该列的 `CellTemplate` 为 `DataGridViewButtonCell`,即可添加按钮到每一行。 接下来,需要在代码中绑定数据源并为每个按钮添加点击事件。可以在 `DataGridView` 的 `DataBindingComplete` 事件中添加以下代码: ```csharp private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { // 遍历每一行,为操作列中的按钮添加事件处理程序 foreach (DataGridViewRow row in dataGridView1.Rows) { var buttonCell = row.Cells["操作"] as DataGridViewButtonCell; if (buttonCell != null) { // 添加按钮点击事件 buttonCell.Value = "点击"; buttonCell.UseColumnTextForButtonValue = true; buttonCell.FlatStyle = FlatStyle.Flat; buttonCell.Style.BackColor = Color.LightGreen; buttonCell.Style.ForeColor = Color.Black; buttonCell.Style.SelectionBackColor = Color.Green; buttonCell.Style.SelectionForeColor = Color.White; buttonCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; buttonCell.Style.Font = new Font("微软雅黑", 9, FontStyle.Regular); buttonCell.ToolTipText = "点击该按钮"; buttonCell.Tag = row.DataBoundItem; // 将当前行绑定的数据赋值给按钮的Tag属性 buttonCell.Click += new DataGridViewCellEventHandler(buttonCell_Click); } } } // 按钮点击事件处理程序 private void buttonCell_Click(object sender, DataGridViewCellEventArgs e) { var buttonCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewButtonCell; if (buttonCell != null) { // 获取按钮所在行绑定的数据 var rowData = buttonCell.Tag as YourDataType; // 处理按钮点击事件 // ... } } ``` 其中,`YourDataType` 为你绑定的数据类型,需要根据实际情况进行替换。在按钮点击事件处理程序中,可以根据获取到的数据进行相应操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值