C# 如何链接两个复选框项目?

C# 如何链接两个复选框项目?,c#,C#,我正在使用复选框显示与表关联的字段名(另一个复选框)。动态生成多个checklistbox,并在检查其中的任何项目时触发事件“OnCheckListBoxItemCheck”。此处选中的当前项是从对象“发件人”获取的。问题是,如何将从动态checklistbox选中的项与从clbtables选中的项关联起来?请帮忙 private void clbTables_ItemCheck(object sender, ItemCheckEventArgs e) { int i

我正在使用复选框显示与表关联的字段名(另一个复选框)。动态生成多个checklistbox,并在检查其中的任何项目时触发事件“OnCheckListBoxItemCheck”。此处选中的当前项是从对象“发件人”获取的。问题是,如何将从动态checklistbox选中的项与从clbtables选中的项关联起来?请帮忙

 private void clbTables_ItemCheck(object sender, ItemCheckEventArgs e)
    {

        int indexofselectedtable;
        indexofselectedtable = Convert.ToInt32(clbTables.SelectedIndex);
        Metadata metadataobj = new Metadata(dbProperties);
        List<string> ColumnNames = new List<string>();
        ColumnNames = metadataobj.GetColumns(clbTables.Items[indexofselectedtable].ToString());
        chklistcolumns = new CheckedListBox();

      //Adds to the Checked ListBox
        for (int j = 0; j < ColumnNames.Count; j++)
        {

            chklistcolumns.Items.Add(ColumnNames.ElementAt(j).ToString());
        }

        this.Controls.Add(chklistcolumns);
        //To fire event for a dynamically generated column checklistboxes
        chklistcolumns.ItemCheck += new ItemCheckEventHandler(OnCheckListBoxItemCheck);
    }
 private void OnCheckListBoxItemCheck(object sender, ItemCheckEventArgs args)
    {
            Columns columnobj = new Columns();
            columnobj.ColumnName = this.chklistcolumns.SelectedItem.ToString(); 
            columnobj.TableName = this.clbTables.SelectedItem.ToString();
            selectedColumnsList.Add(columnobj);

    }
private void clbTables\u ItemCheck(对象发送方,ItemCheckEventArgs e)
{
int indexofselectable;
indexofselectedtable=Convert.ToInt32(clbTables.SelectedIndex);
Metadata metadataobj=新元数据(dbProperties);
List ColumnNames=新列表();
ColumnNames=metadataobj.GetColumns(clbTables.Items[indexofselectedtable].ToString());
chklistcolumns=新的CheckedListBox();
//添加到选中的列表框中
对于(int j=0;j
这也许就是你想要的

checkedListBox1.Items.Add("test");
checkedListBox1.ItemCheck += new ItemCheckEventHandler(checkedListBox1_ItemCheck);

....

void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
    Console.WriteLine(((CheckedListBox)sender).Name + " is the father of item nr: " + e.Index);
    Console.WriteLine("The value of element nr " + e.Index + " is " + ((CheckedListBox)sender).Items[e.Index].ToString());
}

这也许是你想要的

checkedListBox1.Items.Add("test");
checkedListBox1.ItemCheck += new ItemCheckEventHandler(checkedListBox1_ItemCheck);

....

void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
    Console.WriteLine(((CheckedListBox)sender).Name + " is the father of item nr: " + e.Index);
    Console.WriteLine("The value of element nr " + e.Index + " is " + ((CheckedListBox)sender).Items[e.Index].ToString());
}

当选中一个列表中的多个复选框时会发生什么情况?当我使用此选项时,它适用于一个列表中的多个复选框。chklistcolumns…如何识别触发事件的对象的列名?我使用表的selecteditem重命名chklistcolumns。是否有方法从对象发送方获取该信息?
Control cnt=((复选框)发送方)。Parent
?@achilleterzo((复选框)发送方)。Parent返回表单名称。我的“发件人”对象是CheckedListBox中的项目。我不理解您的问题。你到底想做什么?哪部分不起作用?在你发布的长代码中,请指出问题的确切位置,甚至可以编写一些伪代码来显示您希望它执行的操作。当选中一个列表中的多个复选框时会发生什么?在我使用此选项时,对一个列表中的多个复选框很好。chklistcolumns…如何识别引发事件的对象的列名?我使用表的selecteditem重命名chklistcolumns。是否有方法从对象发送方获取该信息?
Control cnt=((复选框)发送方)。Parent
?@achilleterzo((复选框)发送方)。Parent返回表单名称。我的“发件人”对象是CheckedListBox中的项目。我不理解您的问题。你到底想做什么?哪部分不起作用?在您发布的长代码中,请显示问题的确切位置,甚至可以编写一些伪代码来显示您希望它做什么。