题
我在写一C#应用程序(WinForm)与一个列表框具有的内容加入的用户。现在,我可以有一个普通的按钮下列表框中删除的项目,但是我想按钮旁边的内容,因而被内部的列表框。
是这样的:
- 内容1|X
- 内容2|X
- ...
- 内容5|X
问题是我缺少经验。净所以我不知道如何将有可能与所有的自动控制机制。我已经google搜索它,但是没有意义的结果。
任何线索,线索或片段实现这个,欢迎!:)
解决方案 2
因此,一个可能会使一个自定义的控制,但对我的应用程序,它不是真正值得的麻烦。
我所做的是创建一个网格,使它类似于一个列表视图,但与其自己的耀斑。我这么做是因为网格已经有一个buttoncontrol建立在对它的细胞。
是的,我知道,那种臭"黑客",但是它就像一个魅力!:)
道具谢伊Erlichmen谁带领我想我的外部邮件列表框。看看我做什么呢?;)
其他提示
而不是列表框,可以使用列表视图,列表视图的 能力增加自定义列类型.
使用的系统;使用的系统。集合。通用;使用的系统。窗户。形式;
namespace WindowsFormsApplication11 { 公共分类Form1:形式 { 表_items=new List();
public Form1()
{
InitializeComponent();
_items.Add("One");
_items.Add("Two");
_items.Add("Three");
listBox1.DataSource = _items;
}
private void button1_Click(object sender, EventArgs e)
{
// The Add button was clicked.
_items.Add("New item " + DateTime.Now.Second);
// Change the DataSource.
listBox1.DataSource = null;
listBox1.DataSource = _items;
}
private void button2_Click(object sender, EventArgs e)
{
// The Remove button was clicked.
int selectedIndex = listBox1.SelectedIndex;
try
{
// Remove the item in the List.
_items.RemoveAt(selectedIndex);
}
catch
{
}
listBox1.DataSource = null;
listBox1.DataSource = _items;
}
}
}
私人空button1_Click(目的发送者、定引e) { //Add按钮是点击。//...
button2.Enabled = true;
}
私人空button2_Click(目的发送者、定引e) { //Remove按钮是点击。//....
if (listBox1.Items.Count == 0)
{
button2.Enabled = false;
}
}
假设这是一个它应用程序
你需要一定的控制。我会检查的供应商喜欢 http://www.devexpress.com/Products/NET/Controls/WinForms/Editors/editors/ListBoxes.xml 也许有人知道的控制,具体做到这一点。
我不知道你为什么会想做具体地说吗?我会把一个按钮在底部,删除任何选择的项目的列表框。这被认为是通常的方式做这样的事情除非你想到使用能力和把击事件的列表框,发出一个呼叫中删除的项目,如果它存储在数据库或删除的项目从清单上的页面。