473,785 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add files to listview

Wim
I'm trying to add files with a OpenFileDialog to a listview. This is what
I've come up with sofar:

protected void ButAddClick(obj ect sender, System.EventArg s e)
{
OpenFileDialog MyDialog = new OpenFileDialog( );

MyDialog.Multis elect = true ;
MyDialog.Filter = "WAVE files (*.wav)|*.wav|A ll files (*.*)|*.*" ;
MyDialog.Restor eDirectory = true ;
MyDialog.Title = "Add Files";

if (MyDialog.ShowD ialog() == DialogResult.OK )
* foreach (int i in MyDialog.FileNa mes())
* listView.Items. Add(MyDialog.Fi leNames(i), i);
}

But the compiler says: "'System.Window s.Forms.FileDia log.FileNames'
denotes a 'property' where a 'method' was expected" about both lines with
a *.

Could someone explain to me what I'm doing wrong? TIA!

--
Wim
Nov 15 '05 #1
3 8265
Not quite sure about your syntax. The FileNames points to an array. The
syntax for accessing an array in C# is wrong. It should be MyDialog

Few things wrong:

1) The FileNames property points to an array. Your syntax for accessing an
array in C# is wrong. It should be MyDialog.FileNa mes[i].
2) FileNames is an array of strings. Why are you extracting an integer
from the array in your foreach loop? Try "foreach(st ring s in
MyDialog.FileNa mes){listView.I tems.Add(s)}".
3) You never use "()" in a property syntax. This is what your system is
probably complaining about.
"Wim" <wi*@nospam.inv alid> wrote in message
news:Xn******** *************** *******@213.51. 144.36...
I'm trying to add files with a OpenFileDialog to a listview. This is what
I've come up with sofar:

protected void ButAddClick(obj ect sender, System.EventArg s e)
{
OpenFileDialog MyDialog = new OpenFileDialog( );

MyDialog.Multis elect = true ;
MyDialog.Filter = "WAVE files (*.wav)|*.wav|A ll files (*.*)|*.*" ;
MyDialog.Restor eDirectory = true ;
MyDialog.Title = "Add Files";

if (MyDialog.ShowD ialog() == DialogResult.OK )
* foreach (int i in MyDialog.FileNa mes())
* listView.Items. Add(MyDialog.Fi leNames(i), i);
}

But the compiler says: "'System.Window s.Forms.FileDia log.FileNames'
denotes a 'property' where a 'method' was expected" about both lines with
a *.

Could someone explain to me what I'm doing wrong? TIA!

--
Wim

Nov 15 '05 #2
try replacing the lines you have marked with

int i = 0;
foreach (string fName in MyDialog.FileNa mes)
listView.Items. Add(fName, i++);

or

for( int i; i < MyDialog.FileNa mes.Count; i++)
listView.Items. Add( MyDialog.FileNa mes[i], i);


"Wim" <wi*@nospam.inv alid> wrote in message
news:Xn******** *************** *******@213.51. 144.36...
I'm trying to add files with a OpenFileDialog to a listview. This is what
I've come up with sofar:

protected void ButAddClick(obj ect sender, System.EventArg s e)
{
OpenFileDialog MyDialog = new OpenFileDialog( );

MyDialog.Multis elect = true ;
MyDialog.Filter = "WAVE files (*.wav)|*.wav|A ll files (*.*)|*.*" ;
MyDialog.Restor eDirectory = true ;
MyDialog.Title = "Add Files";

if (MyDialog.ShowD ialog() == DialogResult.OK )
* foreach (int i in MyDialog.FileNa mes())
* listView.Items. Add(MyDialog.Fi leNames(i), i);
}

But the compiler says: "'System.Window s.Forms.FileDia log.FileNames'
denotes a 'property' where a 'method' was expected" about both lines with
a *.

Could someone explain to me what I'm doing wrong? TIA!

--
Wim

Nov 15 '05 #3
Wim
Peter and Philip,

Thank you very much. It works like a charm now!

--
Wim
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1980
by: MikeY | last post by:
Hopefully someone can help, I have a listview box where I display my desired files. I single click on the desired file to be renamed and I rename it with a new name. My problem arises when the new name gets displayed through refreshing of my loop and display function. The problem is that when, if I rename the last file entry, everything appears to display fine. If I rename a file above the last entry (bottom entry), two of the new file...
2
3851
by: Xarky | last post by:
Hi, I would like to list all the folders and files on my harddrive in two seperate parts of the window (one part for folders, other part for files). Also, when clicking one of the folders shown, it should open its subfolders and list again its folders and files in the other part of the window. I was trying to use ListView and TreeView components, but I don't have the slightest clue how to use them and if I should use one of those.
1
1426
by: Richard | last post by:
If I'm to make a Listview with a list of files, then how can i get the associated icon to match the file?? Meaning I need the Windows Explorer icons to be the same as in my listview. I can manage everything except getting the icons need help Richard
3
3658
by: ILMergeHelp | last post by:
Hi All, I have an application similar to windows explorer. The problem now is that am not able to sort the folders and files windows explorer style i.e. Ex All folders are sorted in alpha order and then the files. basically grouping files and folders and sorting within the group. If you look at the windows explorer sort style you will know what I want. Has anyone implemeted such sort?
4
5034
by: Peter Pippinger | last post by:
Hello NG, I have written some code which worked fine under c#. But i don´t know, how this shoud work in c++. I have tryed much things, but i can´t find out how to use DirectoryInfo and FileInfo under c++. Thanks for any hints! Peter Here is the c# code:
0
1532
spider1916
by: spider1916 | last post by:
hi there, i need some help on hou to add multiple files selected in an ShowOpen dialog box to my listview. i am using my listview to display all the attached files for an email. i can add a single file at a time but need to add multiple files too. pls help.
0
2180
by: jawilson | last post by:
Hello, I am trying to use drag-n-drop for a listview control in my program. I created a new listview control class (just call it MyListView) that inherits from ListView, and creates a few new properties and methods. I have set AllowDrop to true, and have all of the Drag* events written. In addition, the listview is in the detailed view. A simple explanation of what I want to do is to drag a file from the desktop or explorer into my...
0
1233
by: Peter Hemmingsen | last post by:
Hi We have a directory receiving PDF files from various scanners. I need a simple to browse these files, view them, and based on the content move them to different applications using drag/drop. I've written a very simple Windows app with a list view on the left side and a WebBrowser control on the right side. In the list view I show all PDF files from the directory. When the user click on a file in the list view I show the PDF file in...
4
4518
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea is that when clicking on the "Show details" button the ListView for the appropriate row binds in the codebehind and displays the detail data for the selected row. I did something similar with a gridview control previously, but want to be able to...
0
10336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.