FileNameSelect.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace OTSIncAReportApp._1_UI.OTSTemplateDesigner
  12. {
  13. public partial class FileNameSelect : Form
  14. {
  15. string folderPath = "";
  16. string PathName = "";
  17. public string ChangePathName = "";
  18. public FileNameSelect(string a_Route, string a_PathName)
  19. {
  20. folderPath = a_Route;
  21. PathName = a_PathName;
  22. ChangePathName = a_PathName;
  23. InitializeComponent();
  24. }
  25. private void FileNameSelect_Load(object sender, EventArgs e)
  26. {
  27. listView1.View = View.Details; // 设置视图为Details以显示列标题和子项
  28. listView1.FullRowSelect = true; // 允许整行选择
  29. listView1.CheckBoxes = true; // 允许在项旁边显示勾选框
  30. listView1.Columns.Add("文件名称",229); // 添加列标题
  31. // 获取文件夹中的所有文件信息
  32. FileInfo[] files = new DirectoryInfo(folderPath).GetFiles("*.xml", SearchOption.AllDirectories);
  33. // 遍历文件信息数组并打印出文件名
  34. foreach (FileInfo file in files)
  35. {
  36. listView1.Items.Add(file.Name);
  37. }
  38. listView1.ItemCheck += new ItemCheckEventHandler(listView_ItemCheck);
  39. //label1.Text = PathName;
  40. }
  41. private void button1_Click(object sender, EventArgs e)
  42. {
  43. for (int i = 0; i < listView1.Items.Count; i++)
  44. {
  45. if (listView1.Items[i].Checked)
  46. ChangePathName = listView1.Items[i].Text;
  47. }
  48. this.Close();
  49. }
  50. // 当ListView中的项的检查状态改变时触发的事件处理器
  51. private void listView_ItemCheck(object sender, ItemCheckEventArgs e)
  52. {
  53. for (int i = 0; i < listView1.Items.Count; i++)
  54. {
  55. listView1.Items[i].Checked = false;
  56. }
  57. listView1.Items[e.Index].Checked = true;
  58. }
  59. }
  60. }