私は.net asp.netからC#winformに移行しています。C#winformで複数のファイルを選択
私は、ユーザーがそれらを削除することができ、画面上で選択したファイルを表示し、C#のWinフォーム上で複数のファイルを選択したい...私は、画面のWinフォーム上の項目を示すために使用すべき制御
?
私は.net asp.netからC#winformに移行しています。C#winformで複数のファイルを選択
私は、ユーザーがそれらを削除することができ、画面上で選択したファイルを表示し、C#のWinフォーム上で複数のファイルを選択したい...私は、画面のWinフォーム上の項目を示すために使用すべき制御
?
あなたの質問が正しく理解できたら、リストボックスを使用してください。ユーザーは、通常のWindows Ctrl/Shiftキーを使用してリストボックス内の複数の項目を選択し、選択したい項目をクリックするだけで簡単に選択できます。
以下は、カスタムコントロールのスクリーンショットとコードスニペットです。これはあなた自身の作成の出発点になるはずです。
/// <summary>
/// Retrieve a list of available files in the input directory
/// </summary>
private void LoadAvaliableFiles()
{
try
{
this.lv_AvailableFiles.Items.Clear();
//Pick up files from structure
//Firstly pick up all files in the target directory
string[] filesFound = this.m_watcher.GetFiles();
// Verify that we have some files to display in the list
if (filesFound != null && filesFound.Length > 0)
{
// The ArrayList will contain PreConversionData objects
foreach (string filePath in filesFound)
{
string fileName = Path.GetFileName(filePath);
//create a list view item for the file
ListViewItem newFile = new ListViewItem(fileName);
newFile.Text = fileName;
newFile.ToolTipText = filePath;
newFile.Tag = filePath;
// Add the new item to the list
this.lv_AvailableFiles.Items.Add(newFile);
}
}
this.lv_AvailableFiles.Refresh();
}
catch (Exception ex)
{
Log.WriteLine(Category.Warning, "Exception detected populating the available files list", ex);
}
}
私のコードは、新しく追加されたファイルをキャッチするために、フォルダのウォッチャーを使用しているが、これはdownvotedなぜあなたは同じように簡単に
string [] filesFound = Directory.GetFiles(targetDirectory);
を使用することができますか? – Tigran
@Tigranおそらくそれはほとんど研究努力を示さなかったからです。 (注:私はそれを投票しなかった) –
@devn、あなたのタイトルを変更してください、あなたがASP.NETから来ているという事実は関係ない –