C#-将文本框移动到列表框,并能够使用添加/删除按钮
我有3个文本框,其中包含某些值。根据使用不同正则表达式的字符串所包含的内容,这些值将被拆分 这些文本框位于后台,用户将看不到它们。。但是,我确实希望用户看到对应于每个文本框的列表框这就是下面的代码:C#-将文本框移动到列表框,并能够使用添加/删除按钮,c#,textbox,listbox,datasource,move,C#,Textbox,Listbox,Datasource,Move,我有3个文本框,其中包含某些值。根据使用不同正则表达式的字符串所包含的内容,这些值将被拆分 这些文本框位于后台,用户将看不到它们。。但是,我确实希望用户看到对应于每个文本框的列表框这就是下面的代码: 然而,我的问题是无法移动列表中的每个项目。。。我的意思是,我希望能够有上移,下移,左移,和右移按钮。上移和下移按钮将允许用户在指定列表中上移或下移所选项目(以更改项目顺序)。Move left和Move right按钮将允许用户将当前列表中的项目移动到当前列表的“right”或“left”列表中
然而,我的问题是无法移动列表中的每个项目。。。我的意思是,我希望能够有
上移
,下移
,左移
,和右移
按钮。上移
和下移
按钮将允许用户在指定列表中上移或下移所选项目(以更改项目顺序)。Move left
和Move right
按钮将允许用户将当前列表中的项目移动到当前列表的“right”或“left”列表中
列表框的视觉布局:
我得到了错误:
"Items collection cannot be modified when the DataSource property is set."
上移按钮代码:
向右移动按钮代码:
private void moveRightButton\单击(对象发送者,事件参数e)
{
对于(int i=0;i
问题:
- 有没有办法修改DataSource属性
- 有人想试试这个吗
- 如何更改listFormatHelper()函数以执行所需操作,并允许按钮在没有上述错误的情况下工作
项
属性来填充列表。然后使用Items
属性管理订单,就像您当前尝试的那样如何将数据源转换为一系列对象?与其设置
DataSource
属性,不如使用Items.add()
枚举列表并添加每个项。这是否只是在更改placementOneListBox.DataSource=listOneLines代码>到placementOneListBox.Items.Add(listOneLines)代码>?否,将整个列表对象添加为一项。您需要类似于foreach(listOneLines中的var行)placementOneListBox.Items.Add(行)的内容代码>。很好,在你发布之前我就试过了。到目前为止这似乎奏效了。。让我继续测试。。
placementOneListBox userDefinedListBox placementTwoListBox
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_________________| |_________________| |_________________|
"Items collection cannot be modified when the DataSource property is set."
private void moveUpButton_Click(object sender, EventArgs e)
{
if (placementOneListBox.SelectedIndex != 0 && placementOneListBox.SelectedIndex != -1)
{
object item = placementOneListBox.SelectedItem;
int index = placementOneListBox.SelectedIndex;
placementOneListBox.Items.RemoveAt(index);
placementOneListBox.Items.Insert(index - 1, item);
}
}
private void moveRightButton_Click(object sender, EventArgs e)
{
for (int i = 0; i < placementTwoListBox.Items.Count; i++)
{
userDefinedListBox.Items.Add(placementTwoListBox.Items[i].ToString());
placementTwoListBox.Items.Remove(placementTwoListBox.SelectedItem);
}
}