【问题标题】:How to access the data grid inside a custom control?如何访问自定义控件内的数据网格?
【发布时间】:2018-08-13 01:10:10
【问题描述】:

我是一个新手,我决定使用 Krypton Toolkit 来增强我的程序的 GUI。 我能够将它加载到我的项目中。 我创建了一个名为 mycontrol 的控件的问题,它有一个名为 mydatagrid 的 KryptonDataGridView。

在我的表单中,我有以下代码:

public partial class Form1 : KryptonForm
{
    private KryptonPage[] mycontrolpage;
    private Control mycontrolcontent;
    public Form1()
    {
        InitializeComponent();
    }

    private KryptonPage NewmycontrolPage()
    {
        mycontrolcontent = new mycontrol();
        KryptonPage page = new KryptonPage("mypage", null, "OS mypage");
        // Add the control for display inside the page
        mycontrolcontent.Dock = DockStyle.Fill;
        page.Controls.Add(mycontrolcontent);

        // Document pages cannot be docked or auto hidden
        page.ClearFlags(KryptonPageFlags.DockingAllowAutoHidden | KryptonPageFlags.DockingAllowDocked);

        return page;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        // Setup docking functionality
        KryptonDockingWorkspace w = kryptonDockingManager.ManageWorkspace(kryptonDockableWorkspace);
        kryptonDockingManager.ManageControl(kryptonPanel, w);
        kryptonDockingManager.ManageFloating(this);

        mycontrolpage = new KryptonPage[] { NewmycontrolPage() };
        kryptonDockingManager.AddToWorkspace("Workspace", mycontrolpage);
    }
}

我的问题是如何访问mycontrol中的网格?

【问题讨论】:

  • 我们需要查看mycontrol 类的代码,至少是与 KryptonDataGridView 子控件相关的部分。话虽如此,作为开始,您应该声明您的变量类型为mycontrol,而不是Control。将private Control mycontrolcontent 替换为private mycontrol mycontrolcontent,如果您无法访问该对象的属性,这可以解决您的问题。最后一件事,您应该为控件和变量使用有意义的名称;不要使用像 mycontrol 这样的名字,因为它对阅读代码的其他人(将来可能是你)没有任何意义。

标签: c# winforms krypton-toolkit


【解决方案1】:

没有一些代码,您总是可以查看示例.. 或者 部分代码sn-ps:

    internal ComponentFactory.Krypton.Toolkit.KryptonDataGridView dgvRules;

那么……

            int offset = dgvRules.Rows.Add((bool)condition, name, description, applied);
            KryptonDataGridViewCheckBoxCell dataGridViewCell = dgvRules.Rows[offset].Cells[0] as KryptonDataGridViewCheckBoxCell;
            if (condition == Tribool.Unknown
                || accumulationRules[offset] == Tribool.Unknown)
            {
                dataGridViewCell.ReadOnly = condition == Tribool.Unknown;
                dataGridViewCell.ThreeState = true;
                dataGridViewCell.Value = CheckState.Indeterminate;
            }
            else
            {
                dataGridViewCell.Value = (CheckState)accumulationRules[offset];
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-08
    • 1970-01-01
    • 1970-01-01
    • 2015-10-21
    • 1970-01-01
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多