在windows窗体中添加按钮到datagridview [英] Add buttons to datagridview in windows form

查看:147
本文介绍了在windows窗体中添加按钮到datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在datagridview上添加两个按钮。现在他们在右边。但是我想在左边找到它们。



另一件事是我要为编辑按钮添加一个更新事件。是否

  private void Edit_Click(object sender,EventArgs e)
{

}

表单代码:

  private void Form1_Load(object sender,EventArgs e)
{
// TODO:这行代码将数据加载到qDataSet.Metric表中。
//您可以根据需要移动或移除它。
this.metricTableAdapter.Fill(this.qDataSet.Metric);
DataGridViewButtonColumn EditColumn = new DataGridViewButtonColumn();
EditColumn.Text =编辑;
EditColumn.Name =编辑;
EditColumn.DataPropertyName =编辑;
dataGridView1.Columns.Add(EditColumn);
DataGridViewButtonColumn DelColumn = new DataGridViewButtonColumn();
DelColumn.Text =删除;
DelColumn.Name =删除;
DelColumn.DataPropertyName =删除;
dataGridView1.Columns.Add(DelColumn);
}

图像喜欢:



谢谢。

解决方案

您似乎从设计器中设计了datagridview。



您可以使用允许编辑列的向导。在那里,您将添加两列(一个用于编辑,另一个用于删除)。您可以选择要设置这些列的位置。
按钮的文本使用属性Text定义,您还可以设置属性UseColumnTextForButton。



您可以轻松管理CellContentClickEvent点击的列和行然后执行。



如果要管理访问权限(例如允许某人编辑和其他人不编辑),您可以玩这个列的显示/隐藏。


I want to add two buttons onto datagridview. Now they are on the right side. But I want to locate them on the left.

The other thing is I want to add an update event for "Edit" button. Is it

private void Edit_Click(object sender, EventArgs e)
{

}

Form code:

private void Form1_Load(object sender, EventArgs e)
{
   // TODO: This line of code loads data into the 'qDataSet.Metric' table. 
   // You can move, or remove it, as needed.
   this.metricTableAdapter.Fill(this.qDataSet.Metric);
   DataGridViewButtonColumn EditColumn = new DataGridViewButtonColumn();
   EditColumn.Text = "Edit";
   EditColumn.Name = "Edit";
   EditColumn.DataPropertyName = "Edit";
   dataGridView1.Columns.Add(EditColumn);
   DataGridViewButtonColumn DelColumn = new DataGridViewButtonColumn();
   DelColumn.Text = "Delete";
   DelColumn.Name = "Delete";
   DelColumn.DataPropertyName = "Delete";
   dataGridView1.Columns.Add(DelColumn);
}

The image likes:

Thank you.

解决方案

You seems to have design the datagridview from the designer.

You can use the wizard which allow to edit columns. There you'll add two columns (one for editing and the other for deleting). You can choose where you want to set those columns. The text of the button is defined using the property "Text", you can also set the property "UseColumnTextForButton".

You can manage easily in the CellContentClickEvent the column and row which is clicked and then do the job.

If you want to manage access right (like allowing someone to editing and someone else to not editing) you can play with show/hide of this column.

这篇关于在windows窗体中添加按钮到datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆