第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C# WinForms ListView 不顯示項目/文件/文件夾

C# WinForms ListView 不顯示項目/文件/文件夾

C#
瀟湘沐 2023-06-25 14:27:02
我想在列表視圖中顯示文件名,但問題是列表視圖沒有顯示任何項目。奇怪的部分是 listview.items.count 表明項目已正確添加。項目只是不顯示在任何類型的 listview.view 中。編輯:ListView 被拖放到選項卡控件上。string[] files;bool error = false;    try       {                  files = Directory.GetFiles(addDir /* this is the folder path*/, "*.txt", SearchOption.AllDirectories);    }    catch(Exception ex)    {        // the code will jump here if there any access restrictions        MessageBox.Show(ex.Message);        error = true;    }    if(!error)    {        foreach (string fi in files)        {            string fnameonly = System.IO.Path.GetFileNameWithoutExtension(fi);            _listView1.Items.Add(fnameonly);        }    }
查看完整描述

2 回答

?
茅侃侃

TA貢獻1842條經(jīng)驗 獲得超21個贊

有時它有助于創(chuàng)建一個新項目,驗證它是否有效,然后添加更多功能,直到您了解是什么破壞了您的程序。下面的示例僅顯示一個包含兩個文件的 ListView。確保這適用于您的機器。然后慢慢添加更多代碼并始終檢查您的程序是否仍然有效。我將所有代碼放在一個文件中,因為在堆棧溢出上發(fā)布更容易,但您可以將其拆分為單獨的文件。

using System;

using System.IO;

using System.Windows.Forms;


namespace WindowsFormsApp

{

? ? public class ListViewDemo : Form

? ? {

? ? ? ? public ListViewDemo()

? ? ? ? {

? ? ? ? ? ? var _listView1 = new ListView();


? ? ? ? ? ? string[] files = { @"C:\tmp\file1.txt", @"c:\path\to\file2.doc" };

? ? ? ? ? ? foreach (string fi in files)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? string fnameonly = Path.GetFileNameWithoutExtension(fi);

? ? ? ? ? ? ? ? _listView1.Items.Add(fnameonly);

? ? ? ? ? ? }


? ? ? ? ? ? AutoSize = true;

? ? ? ? ? ? Controls.Add(_listView1);? ??

? ? ? ? }

? ? }


? ? static class Program

? ? {? ??

? ? ? ? [STAThread]

? ? ? ? static void Main()

? ? ? ? {

? ? ? ? ? ? Application.Run(new ListViewDemo());

? ? ? ? }

? ? }

}


查看完整回答
反對 回復 2023-06-25
?
繁華開滿天機

TA貢獻1816條經(jīng)驗 獲得超4個贊

這是一個非常愚蠢的錯誤,花了幾天時間才發(fā)現(xiàn)。不小心將內(nèi)存分配給了通過拖放操作創(chuàng)建的 ListView 控件。



查看完整回答
反對 回復 2023-06-25
  • 2 回答
  • 0 關(guān)注
  • 253 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號