Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#选中列表框_C#_Linq_Checkedlistbox - Fatal编程技术网

C#选中列表框

C#选中列表框,c#,linq,checkedlistbox,C#,Linq,Checkedlistbox,我试图允许用户使用名为tableCheckedListBox的CheckedListBox选择一个“表名”。一旦用户检查一个或多个tableCheckedListBox项目(即“表名”),第二个CheckedListBox名为columnCheckedListBox的项目(即“列名”)应填充与tableCheckedListBox中选中的“表名”相关联的一组项目(即“列名”) 一旦用户在表checkedListBox中选中“表名”,我就无法填充相关的列checkedListBox(即“列名”)。

我试图允许用户使用名为tableCheckedListBox的
CheckedListBox
选择一个“表名”。一旦用户检查一个或多个
tableCheckedListBox
项目(即“表名”),第二个
CheckedListBox
名为columnCheckedListBox的项目(即“列名”)应填充与
tableCheckedListBox
中选中的“表名”相关联的一组项目(即“列名”)

一旦用户在
表checkedListBox
中选中“表名”,我就无法填充相关的
列checkedListBox
(即“列名”)。(仅供参考-我使用LINQ to SQL来创建表示数据库中“表名”的类。这些类(即“表名”)成功地填充到
tableCheckedListBox
;相反,我在将类中的属性(即“列名”)填充到
columnCheckedListBox
)时遇到问题

这是我一直在做的事情

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Data.Linq.Mapping;

namespace QueryBuilder
{
    public partial class FrmQueryBuilder : Form
    {

        public FrmQueryBuilder();
        {
            InitializeComponent();
        }

        public void Form1_Load(object sender, EventArgs e)
        {
            PropertyInfo[] properties = typeof(DBClassDataContext).GetProperties();

            foreach (PropertyInfo property in properties)
            {
                if (property.PropertyType.IsClass)
                {
                    object[] attributes = property.PropertyType.GetGenericArguments()[0].GetCustomAttributes(typeof(TableAttribute), false);

                    if (attributes.Length > 0)
                    {
                        tableCheckedListBox.Items.Add(property.Name);
                    }
                }
            }
        }

        private void tableCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            PropertyInfo[] tableColumns1 = typeof(TABLENAMEONE).GetProperties();
            PropertyInfo[] tableColumns2 = typeof(TABLENAMETWO).GetProperties();
            PropertyInfo[] tableColumns3 = typeof(TABLENAMETHREE).GetProperties();

            foreach (PropertyInfo columns1 in tableColumns1)
            {
                if (columns1.PropertyType.IsClass)
                {
                    object[] colAttrib1 = columns1.PropertyType.GetGenericArguments()[0].GetCustomAttributes(typeof(ColumnAttribute), false);

                    if (colAttrib1.Length > 0)
                    {
                        tableCheckedListBox.Items.Add(columns1.Name);
                    }
                }
            }

            foreach (PropertyInfo columns2 in tableColumns2)
            {
                if (columns2.PropertyType.IsClass)
                {
                    object[] colAttrib2 = columns2.PropertyType.GetGenericArguments()[0].GetCustomAttributes(typeof(ColumnAttribute), false);

                    if (colAttrib2.Length > 0)
                    {
                        tableCheckedListBox.Items.Add(columns2.Name);
                    }
                }
            }

            foreach (PropertyInfo columns3 in tableColumns3)
            {
                if (columns3.PropertyType.IsClass)
                {
                    object[] colAttrib3 = columns3.PropertyType.GetGenericArguments()[0].GetCustomAttributes(typeof(ColumnAttribute), false);

                    if (colAttrib3.Length > 0)
                    {
                        tableCheckedListBox.Items.Add(columns3.Name);
                    }
                }
            }
        }

        private void columnCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
        {

        }
    }
}

什么不起作用?当我实例化columnCheckedListBox方法成功执行的一个类时,应该尝试将代码缩小到与tableCheckedListBox方法中的问题相关的部分(即,错误可能不在空方法中)。当我希望选中多个tableCheckedListBox时,问题就开始了。我需要关于填充多个tableCheckedListBox列名的帮助。我希望这一评论更清楚。