在PreviewDrop事件之后将项添加到ListBox。 [英] Add items to a ListBox after a PreviewDrop event.

查看:84
本文介绍了在PreviewDrop事件之后将项添加到ListBox。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。



新手问题。



我有一堆列表框绑定每一个在类中创建的不同ObservableCollection。



列表框的名称与ObservableCollections的名称相匹配。



删除不同的项目listboxes为您提供了已删除的Listbox的名称(此代码位于创建列表框的其他类中)



 private void ListBox_PreviewDrop(object sender,DragEventArgs e)
{
var source = e.Source as ListBox;
string goesto = source.Name.ToString();

}





我的问题:



我怎样才能将一个项目添加到名为e.Source.Name值的ListBox中?



希望有人理解这个问题......它只是a在检索完放图的ListBox的名称后,向该ListBox添加一个项目类似



 listbox(goesto) .Items.Add(SomeItem); 





谢谢!

解决方案

  var  source = e.Source  as  ListBox; 
if (source!= null
source.Items.Add(source .Name.ToString());


Hi.

Newbie question here.

I have a bunch of listboxes bound each one to a different ObservableCollection created inside a class.

The names of the listboxes matches the names of the ObservableCollections.

Dropping an item inside the different listboxes gives you the name of the Listbox where it has dropped (this code is in a different class where the listbox was created)

private void ListBox_PreviewDrop(object sender, DragEventArgs e)
    {
        var source = e.Source as ListBox;
        string goesto = source.Name.ToString();
        
}



My question:

How could i add an item to that ListBox named exactly as the e.Source.Name value???

Hope someone understand the question... it is just a "After retrieving the name of the ListBox where the drop was done, add an item to that ListBox" Something like

listbox(goesto).Items.Add(SomeItem);



Thank you!

解决方案

var source = e.Source as ListBox;
if(source != null)
 source.Items.Add(source.Name.ToString());


这篇关于在PreviewDrop事件之后将项添加到ListBox。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆