【问题标题】:How to make CheckBox as checked and unchecked so that user can modify it in Grid Control?如何使 CheckBox 处于选中状态和未选中状态,以便用户可以在 Grid Control 中对其进行修改?
【发布时间】:2017-03-16 04:23:29
【问题描述】:

我设计了一个有 20 行和 3 列的grid control。 在第一列中,我放置了一些硬编码的字符串,在第二列中,我想将 checkBox 与已检查的未检查行为放在一起,以便用户可以修改它。我在下面的代码中的 QueryCellInfo 事件中为此编写了代码,但它不是工作。

如何完成?

请推荐。

以下是我的部分代码:

public partial class Form1 : Form
{
    System.Windows.Forms.Timer t1 = new System.Windows.Forms.Timer();
    private Syncfusion.Windows.Forms.Grid.GridControl gridControlDownloadScript = new Syncfusion.Windows.Forms.Grid.GridControl();
    public Form1()
    {
       // this.gridControl1.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Metro;
        InitializeComponent();

    }

    private void Form1_Load(object sender, EventArgs e)
    {

        gridControl1.Model.RowCount = 20;
        gridControl1.Model.ColCount = 3;
        this.gridControl1.VScrollPixel = true;
        this.gridControl1.HScrollPixel = true;


        this.gridControl1[0, 1].Text = "EMPLOYEE";
        this.gridControl1[0, 2].Text = "CHECKBOX";
        this.gridControl1[0, 3].Text = " ";
        this.gridControl1[1, 1].Text = "Rahul Verma";
        this.gridControl1[2, 1].Text = "MAnish Desai";
        this.gridControl1[3, 1].Text = "Mohan Pothala";
        this.gridControl1[4, 1].Text = "Dhanraj Dhoke";

        gridControl1.Model.RowCount = 20;

        gridControl1.Model.ColCount = 3;
        gridControl1.QueryCellInfo += new GridQueryCellInfoEventHandler(GridQueryCellInfo);
        gridControl1.SaveCellInfo += new GridSaveCellInfoEventHandler(GridSaveCellInfo);
        gridControl1.QueryRowCount += gridControl1_QueryRowCount;
        gridControl1.QueryColCount += gridControl1_QueryColCount;
        this.gridControl1.HScrollBehavior = GridScrollbarMode.Disabled; 
        this.gridControl1.VScrollBehavior = GridScrollbarMode.Disabled;

        this.gridControl1.ColWidths.ResizeToFit(GridRangeInfo.Cols(1, 1));

        this.gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Rows(1, 20));


        t1.Interval = 250;

        t1.Tick += new EventHandler(IncreaseProgressBar);



    }

    private void CellClick(object sender, GridCellClickEventArgs e)
    {
    }



    private void IncreaseProgressBar(object sender, EventArgs e)
    {
        progressBar1.Increment(5);
        progressBar1.Minimum = 0;
        progressBar1.Maximum = 100;


        lblProgress.Text = progressBar1.Value.ToString() + "%";

        if (progressBar1.Value == progressBar1.Maximum)

            t1.Stop();
    }

    private void gridControl1_QueryColCount(object sender, GridRowColCountEventArgs e)
    {

    }

    private void gridControl1_QueryRowCount(object sender, GridRowColCountEventArgs e)
    {

    }

    private void GridQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
    {
        int i = 0;
        while (i++ < 4)
        {
            if (i == 0 || i == 1 || i == 4 || i == 6 || i == 9 || i == 11 || i == 14)
            {

                continue;

            }
            else if (e.RowIndex == i && e.ColIndex == 2)
            {

                e.Style.CellType = GridCellTypeName.CheckBox;

                e.Style.Description = "";
        this.gridControl1[i, 2].CheckBoxOptions = new GridCheckBoxCellInfo("True", "False", string.Empty, false);
                e.Style.CheckBoxOptions.CheckedValue = "true";
                e.Style.CellValue = "true";

            }

        }
        if (e.RowIndex > 0 && e.ColIndex > 0)
        {


        }
    }

【问题讨论】:

  • 您使用的技术是什么?赢得表格? WPF?另外,“按需”是什么意思,您只希望用户修改它们吗?
  • @Emad ,我正在使用 win forms。是的,我希望用户修改它们。很抱歉造成混乱。

标签: c# checkbox syncfusion gridcontrol


【解决方案1】:

您可以使用网格属性手动执行此操作定义列属性手动将列设置为复选框,然后它将按照您的意愿运行

【讨论】:

    【解决方案2】:

    QueryCellInfo 事件将为 GridControl 中的每个 cell 触发。根据您的代码,您已在 QueryCellInfo 事件中将单元格值设置为 true。所以 CheckBoxCellValue 将一直保持为 True。如果您希望用户修改 CheckedValue,请在 Form_Load() 方法中将该特定单元格的 CellValue 设置为“True”。请参考以下代码, 代码sn-p this.gridControl1[2, 2].CellValue = "True"; this.gridControl1[3, 2].CellValue = "True";

    Screenshot Sample Link

    注意 如果您对 Syncfusion 控件有任何其他疑问,请考虑创建support ticketposting in the forums

    【讨论】:

      猜你喜欢
      • 2021-03-11
      • 2016-07-16
      • 2015-05-21
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      相关资源
      最近更新 更多