.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 16th, 2004, 12:40 PM
Natti Natti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Finland
Posts: 3 Natti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
vc++ .net: Adding files from a directory to a listbox

I already posted this to the other c/c++ forums here on devshed, but thought that this might be in the "right" place here. Sorry for makeing two posts, but yes..

Im trying to add filenames from a directory to an itembox.
I modified the code @ URL to look like this:
Code:
#include "stdafx.h"
#include <iostream>
#include <io.h>
#include <string>

using namespace std;

void listDir(const char * sdir, int count){
    string str, strDir, str1;
    struct _finddata_t c_file;
    long hFile;

    // Find first file in current directory
    str = sdir + (string) "\\*";
    if( (hFile = _findfirst( str.c_str(), &c_file )) == -1L ){
        fprintf(stderr, "Error opening %s!\n", str.c_str());
        return;
    }

	while(_findnext( hFile, &c_file ) == 0)
	{
		if ((strcmp(c_file.name, ".") == 0 ||  strcmp(c_file.name, "..") == 0)) {
        continue;
        }
		str1 = c_file.name;
		unsigned int loc = str1.find( ".GIF" );
	    if( loc != string::npos )
	    {
			listBox1->Items->Add(str1);
			// cout << str1 << endl;
	    }
	}
   _findclose( hFile );
   return;
}

First i just made the program to write the filenames on the screen as a console program to see if it only writes .gif files, that worked just fine. I then replace the cout with the listBox1->items->add(str1) so that it would add the filenames to the listbox.

When i try to use it in my c++ .net application i call the function like this:

Code:
	private: System::Void button1_Click(System::Object *  sender, System::EventArgs *  e)
			 {
				 ListDir(textBox1->Text, 0);
			 }


Why do i do it like this?. Well i just want to write the directory path into an textbox and when i press the ok button (button1) i made i want the listdir function to pass the textbox1->text as a directory. But the error message i get is this:

Form1.h(112): error C2664: 'DirList::listDir' : cannot convert parameter 1 from 'System::String __gc *' to 'const char *'

I know what it means, but i don't know how to fix it because im new to c++ and .NET, any help would be nice. thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > vc++ .net: Adding files from a directory to a listbox


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT