动态复选框列表
我目前正在构建一个动态 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该将 CheckedListBox 作为项目添加到 CheckedListBox。尝试仅添加 URLName 字符串,即
我认为这就是您想要实现的目标。
You shouldn't be adding a CheckedListBox as an item to a CheckedListBox. Try just adding the URLName string instead, i.e.
I think that is what you are trying to achieve.