动态复选框列表

发布于 2024-10-10 07:34:01 字数 1988 浏览 3 评论 0原文

我目前正在构建一个动态 url 选项卡系统,用户可以说出他们想要在选项卡页控件上显示的 url。

在数据库中我有以下列。

用户ID,整数 URL 名称变量 启用位

我正在拉回数据,但我正在尝试做的是在用户选项页面上使用 urlname 及其状态填充复选框列表,以便他们可以说出他们想要显示的选项卡。

我编写了以下方法来获取网址并创建复选框,但是我不断收到以下错误。

ex = {"InvalidArgument='1' 的值对于 'index' 无效。\r\n参数名称:index"}

它读取第一行正常,但当它到达返回的第二行时,我收到该错误。

有人有什么想法吗?

谢谢

private void GetUserURLS()
    {

        db.initiateCommand("[Settings].[LoadAllUserURLS]", CommandType.StoredProcedure);

        sqlp = db.addParameter("@UserID", _UserID, SqlDbType.Int, ParameterDirection.Input);
        sqlp = db.addParameter("@spErrorID", DBNull.Value, SqlDbType.Int, ParameterDirection.InputOutput);

        db.executeCommand();

        CreateCheckBoxes(db.getTable(0).Rows);
        db.releaseCommand();
    }


    private void CreateCheckBoxes(DataRowCollection rows)
    {
        try
        {
            int i = 0;
            foreach (DataRow row in rows)
            {
                //Gets the url name and path when the status is enabled. The status of Enabled / Disabled is setup in the users option page
                string URLName = row["URLName"].ToString();
                bool enabled = Convert.ToBoolean(row["Enabled"]);

                CheckedListBox CB = new CheckedListBox();              
                CB.Items.Insert(i, URLName);

                CB.Tag = "CB" + i.ToString();

                checkedListBox1.Items.Add(CB);

                i++;
            }
        }

        catch (Exception ex)
        {
            //Log error
            Functionality func = new Functionality();
            func.LogError(ex);

            //Error message the user will see
            string FriendlyError = "There has been populating checkboxes with the urls - A notification has been sent to development";
            Classes.ShowMessageBox.MsgBox(FriendlyError, "There has been an Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

I am currently building a dynamic url tab system that user can say what urls they want to be displayed on a tabpage control.

In the database i have the following columns.

userID, int
URLName var
Enabled bit

I am pulling the data back ok but what i am trying do is populate a checkbox list with the urlname and its status on a user options page so they can say what tabs they want displayed.

I have wrote the following methods to get the urls and create the checkboxes however i keep getting the following error.

ex = {"InvalidArgument=Value of '1' is not valid for 'index'.\r\nParameter name: index"}

It reads the first row ok but when it hits the 2nd row that is being returned i get that error.

Has anyone got any ideas?

Thanks

private void GetUserURLS()
    {

        db.initiateCommand("[Settings].[LoadAllUserURLS]", CommandType.StoredProcedure);

        sqlp = db.addParameter("@UserID", _UserID, SqlDbType.Int, ParameterDirection.Input);
        sqlp = db.addParameter("@spErrorID", DBNull.Value, SqlDbType.Int, ParameterDirection.InputOutput);

        db.executeCommand();

        CreateCheckBoxes(db.getTable(0).Rows);
        db.releaseCommand();
    }


    private void CreateCheckBoxes(DataRowCollection rows)
    {
        try
        {
            int i = 0;
            foreach (DataRow row in rows)
            {
                //Gets the url name and path when the status is enabled. The status of Enabled / Disabled is setup in the users option page
                string URLName = row["URLName"].ToString();
                bool enabled = Convert.ToBoolean(row["Enabled"]);

                CheckedListBox CB = new CheckedListBox();              
                CB.Items.Insert(i, URLName);

                CB.Tag = "CB" + i.ToString();

                checkedListBox1.Items.Add(CB);

                i++;
            }
        }

        catch (Exception ex)
        {
            //Log error
            Functionality func = new Functionality();
            func.LogError(ex);

            //Error message the user will see
            string FriendlyError = "There has been populating checkboxes with the urls - A notification has been sent to development";
            Classes.ShowMessageBox.MsgBox(FriendlyError, "There has been an Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福丶如此 2024-10-17 07:34:01

您不应该将 CheckedListBox 作为项目添加到 CheckedListBox。尝试仅添加 URLName 字符串,即

            string URLName = row["URLName"].ToString();
            bool enabled = Convert.ToBoolean(row["Enabled"]);

            checkedListBox1.Items.Add(URLName, enabled);

我认为这就是您想要实现的目标。

You shouldn't be adding a CheckedListBox as an item to a CheckedListBox. Try just adding the URLName string instead, i.e.

            string URLName = row["URLName"].ToString();
            bool enabled = Convert.ToBoolean(row["Enabled"]);

            checkedListBox1.Items.Add(URLName, enabled);

I think that is what you are trying to achieve.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文