简体   繁体   English

如何将组合框或复选框添加到“ Datagridview”的现有记录中而不是在新列中

[英]How to add combobox or checkbox to existing record of “Datagridview” not in a new column

In my code I want to add checkbox to "Datagridview" results, I have already find solutions how to add combobox or checkbox for datagridview but with ADDING NEW COLUMN, I want to add the checkbox to existing result, I'll explain to you in details, 在我的代码中,我想向“ Datagridview”结果中添加复选框,我已经找到了如何为datagridview添加组合框或复选框的解决方案,但是通过添加新列,我想将复选框添加到现有结果中,我将在细节,

If I have a results for "Select statement" to show this data: 如果我有一个“选择语句”的结果来显示此数据: 在此处输入图片说明

I don't want to add new column at last or first, i want to put the checkboxes at the last column "Status" (which is coming from database) , to modify its result and update the existing records at the database for same column. 我不想最后或首先添加新列,我想将复选框放在“状态”(来自数据库)的最后一列,以修改其结果并更新数据库中同一列的现有记录。

Or to add combobox for this column with predefined collection to let the user to modify the status from "pending" to "accepted" or "rejected" but in same record not in a new column. 或为具有预定义集合的此列添加组合框,以使用户将状态从“待定”修改为“接受”或“拒绝”,但在同一记录中不在新列中。

This is what I want to do: 这就是我想做的:
在此处输入图片说明

public Form1()
{
        InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
        AddComboxBoxControlsInGridViewColumn();
}

private void AddComboxBoxControlsInGridViewColumn()
{
    DataTable dt = new DataTable();
    dt.Columns.Add("Status");
    for (int j = 0; j < 10; j++)
    {
        dt.Rows.Add("");
    }
    this.dataGridView1.DataSource = dt;
    this.dataGridView1.Columns[0].Width = 200;

    DataGridViewComboBoxCell ComboBoxCell = new DataGridViewComboBoxCell();
    ComboBoxCell.Items.AddRange(new string[] { "Pending","Accepted","Rejected" });
    this.dataGridView1[0, 0] = ComboBoxCell;
    this.dataGridView1[0, 0].Value = "Accepted";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM