相关疑难解决方法(0)

禁用datagridview中的按钮列

我有一个数据网格视图有4列,前两列是组合框列,第三列是文本框列,第四列是按钮列.在表单加载我必须禁用datagrid的整个按钮列,在此之后我应该选择前三列和保存后,将这三个列保存在数据库中,特定行中的按钮列应该启用.应该通过单击按钮将第一列保存在数据库中.请帮助我解决这个问题很多天这里是我使用的代码

private void SATAddTemplate_Load(object sender, EventArgs e)
{
           foreach (DataGridViewRow row in datagrdADDTEMP.Rows)
           {

               DataGridViewButtonCell btn = (DataGridViewButtonCell)row.Cells[3];
               btn.ReadOnly = true;
           }
}
 private void btnSaveSettings_Click(object sender, EventArgs e)
     {
           foreach (DataGridViewRow row in datagrdADDTEMP.Rows)
           {

               DataGridViewButtonCell btn = (DataGridViewButtonCell)row.Cells[3];
               btn.ReadOnly = false;
           }
     }
Run Code Online (Sandbox Code Playgroud)

c# datagridview

11
推荐指数
2
解决办法
3万
查看次数

DataGridView中的单元格格式在DataBindingComplete上

我对其中一个工作项目的要求存在问题.我正在做的是将数据表绑定到DataGridView(DGV)的数据源.然后我遍历DataGridView并检查单元格的值是否为1*或2**,并使用工具提示和红色背景格式化这些单元格.如果我使用按钮事件触发这一切,一切都很好.但是,如果我希望在使用DataBindingComplete事件加载表单时自动执行此操作,则它无法正常工作.问题是DataBindingComplete多次触发.我读了这个问题,这给了我一些选择尝试,没有一个工作.这是代码:

public partial class TestForm2 : Form
{
    private DataTable dt;
    private int methodCalls = 0;
    private bool isFormatted = false;

    public TestForm2()
    {
        InitializeComponent();
        buildDataTable();
        dataGridView1.DataBindingComplete += dataGridView1_DataBindingComplete;
    }

    private void TestForm2_Load(object sender, EventArgs e)
    {
        bindData();
    }

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

    private void bindData()
    {
        dataGridView1.DataSource = dt;
    }

    private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
    {
        //If this code is commented out the program will work just fine 
        //by just clicking …
Run Code Online (Sandbox Code Playgroud)

c# data-binding datagridview event-handling

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×2

datagridview ×2

data-binding ×1

event-handling ×1