【问题标题】:DataGrid Drag & Drop数据网格拖放
【发布时间】:2011-11-05 04:46:28
【问题描述】:

我有一个 WPF 对话框,上面有一个 DataGrid。我想要做的是能够将文件或文件夹拖放到 Datagrid 上并显示信息。每行将代表每个文件。对于我的生活,我无法弄清楚如何插入数据并显示行。

这是掉落代码...

public partial class SplitWindow : UserControl
{

    public SplitWindow()
    {
       this.InitializeComponent();
    }

    private void FilesDropped(object sender, System.Windows.DragEventArgs e)
    {

       if (e.Data.GetDataPresent(DataFormats.FileDrop))
       {
           DropDataGrid.Items.Clear(); 

           string[] droppedFilePaths = e.Data.GetData(DataFormats.FileDrop, true) as string[];

           foreach (string droppedFilePath in droppedFilePaths)
           {
               string name =          System.IO.Path.GetFileNameWithoutExtension(droppedFilePath);
               // insert row???
           }
       }
    }
}

【问题讨论】:

    标签: c# wpf datagrid


    【解决方案1】:
    1. 创建 ObservableCollection
    2. 将该集合设置为 DataGrid 的 ItemsSource
    3. 将文件名添加到集合中。

    您必须弄乱 xaml 才能使事情看起来正确。

    【讨论】:

    • 你能给我一个编码示例吗?
    猜你喜欢
    • 2013-07-15
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-23
    相关资源
    最近更新 更多