
-----------------------------------
RealityFix
Tue Nov 17, 2009 9:11 am

Opening Files[C Sharp]
-----------------------------------
What I basically want to do is open a file and make the program grab the files that are in the folder. Oh have some sort of way to use two files at once. 

Im making a little program where a person makes  a list of players and monsters and I hate using datafiles. I kinda suck at them >.> 
So I just think it would be easier to use two seperate files then one file holding monsters and players.  

Any tips? or Better ways to pull this off?

-----------------------------------
rdrake
Tue Nov 17, 2009 10:23 am

RE:Opening Files[C Sharp]
-----------------------------------
Check out the following static method.

System.IO.Directory.GetDirectories(string dir).

Personally I'd look into serialization in order to store your settings and states.  It's pretty easy.

-----------------------------------
RealityFix
Wed Nov 18, 2009 5:27 pm

RE:Opening Files[C Sharp]
-----------------------------------
Any links to that serialization? I just want the easiest way possible at doing this >.> 

Me = crappy at datafiles ;_;

-----------------------------------
jbking
Wed Nov 18, 2009 5:41 pm

Re: Opening Files[C Sharp]
-----------------------------------
What I basically want to do is open a file and make the program grab the files that are in the folder. Oh have some sort of way to use two files at once. 

Im making a little program where a person makes  a list of players and monsters and I hate using datafiles. I kinda suck at them >.> 
So I just think it would be easier to use two seperate files then one file holding monsters and players.  

Any tips? or Better ways to pull this off?

Why not use a command line interface to input data?  Under the command line interface you could ask how many players and monsters should be generated, name them and then build the lists from some simple input.  You don't need no stinkin' no files, IOW.

-----------------------------------
rdrake
Wed Nov 18, 2009 5:41 pm

RE:Opening Files[C Sharp]
-----------------------------------
http://www.switchonthecode.com/tutorials/csharp-tutorial-serialize-objects-to-a-file

-----------------------------------
RealityFix
Thu Nov 19, 2009 1:47 pm

RE:Opening Files[C Sharp]
-----------------------------------
this program has to use datafiles. Its what the whole assignment is about. The user has to be able to save and open the files and such. 

Thanks rdrake.

The site uses some functions we haven't been taught yet in C#. 

Is there a slight possibility of a easier technique?

-----------------------------------
jbking
Thu Nov 19, 2009 2:15 pm

Re: RE:Opening Files[C Sharp]
-----------------------------------
this program has to use datafiles. Its what the whole assignment is about. The user has to be able to save and open the files and such. 

Ah, that wasn't stated in the initial post.  Some people do these kinds of things for fun.  :twisted:

-----------------------------------
RealityFix
Sat Nov 21, 2009 3:59 pm

RE:Opening Files[C Sharp]
-----------------------------------
Well I'm not having fun with this >.> To damn irritating.

-----------------------------------
RealityFix
Mon Nov 23, 2009 3:59 pm

RE:Opening Files[C Sharp]
-----------------------------------
Hate to double post but I get this weird error and i have no idea what to do with it >.>


Error	1	Static member 'DungeonsAndDragons.SearchAndSort.Shell(string

I have no idea what this is T_T

-----------------------------------
rdrake
Mon Nov 23, 2009 4:04 pm

RE:Opening Files[C Sharp]
-----------------------------------
You're accessing a static method on an instance variable instead of the type.  Post the code that's giving you the error if you're still stuck.

-----------------------------------
RealityFix
Mon Nov 23, 2009 4:59 pm

RE:Opening Files[C Sharp]
-----------------------------------
The code is a little confusing. I didn't write the search and sort thing I grabbed it off my teacher (Im a lazy bugger when it comes down to it) 

but what I think your saying is that because my search thing is a static and my OpenFile method is just a public void that it will not work right? 


//(public void OpenFile)
  try
            {

                openFileDialog1.Reset();
                openFileDialog1.InitialDirectory = Application.ExecutablePath;
                openFileDialog1.Filter = "Text files (*.txt)|*.txt|" + "All files|*.*";
                openFileDialog1.FilterIndex = 1;

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    //string s = Application.StartupPath;
                    //string f = s + @"\albums.txt";

                    FileName = openFileDialog1.FileName;
                    r = new StreamReader(FileName);

                    string WholeLine;

                    while ((WholeLine = r.ReadLine()) != null)
                    {
                        c++;
                        lines = WholeLine.Split(',');
                        NameMon


 public static void Shell(string

-----------------------------------
rdrake
Mon Nov 23, 2009 5:06 pm

RE:Opening Files[C Sharp]
-----------------------------------
Search.Shell(NameMon, borrower, n); Is "Search" an object or the name of the class where Shell() is?

If it's an object then you're doing it wrong.  Call this instead.
SearchAndSort.Shell()

-----------------------------------
RealityFix
Mon Nov 23, 2009 5:28 pm

RE:Opening Files[C Sharp]
-----------------------------------

SearchAndSort Search = new SearchAndSort();


Sorry forgot to include the part above the try{}.

-----------------------------------
rdrake
Mon Nov 23, 2009 6:34 pm

RE:Opening Files[C Sharp]
-----------------------------------
Yup, doing it wrong.  The method is static, you absolutely have to call it as such.

SearchAndSort.Shell(NameMon, borrower, n);

Notice how I'm calling the method on the class name, not an instance of that class.  Try the above code and it should work just fine.

Also please in the future try to be a bit more careful when including bits of code in your post.  Some of your questions are hard to understand due to missing code fragments.  You're better off including too much than not enough.

-----------------------------------
RealityFix
Mon Nov 23, 2009 7:20 pm

RE:Opening Files[C Sharp]
-----------------------------------
Thanks! 

And I will put more data in my questions in the future.

-----------------------------------
RealityFix
Mon Nov 23, 2009 8:12 pm

RE:Opening Files[C Sharp]
-----------------------------------
Im gonna do another double post here since there is no real point in starting a new thread for such a small question:

When using a ListView how do i add text to it in details mode? I know how to add columns and such but how do i get the data under each one? 

E.g. Putting Bob under the Names column, and putting 13 under the Age column? 

I looked a lot on google but a lot of there stuff is overly complicated for what I want to do. Im just transferring text from a textbox.

-----------------------------------
rdrake
Mon Nov 23, 2009 11:06 pm

RE:Opening Files[C Sharp]
-----------------------------------
ListViewItem lvi = new ListViewItem("Bob");
lvi.SubItems.Add("13");
lvi.SubItems.Add("Other stuff");

-----------------------------------
RealityFix
Tue Nov 24, 2009 3:21 pm

RE:Opening Files[C Sharp]
-----------------------------------
Thanks ever so much ^_^ 

Your probably one of the few mods I've seen on a forum that do something. 

I would give karma but I need to post more >.>

I donated some bits to ya instead, its only 20 but thats a pretty good amount for the number of posts that i have.

-----------------------------------
RealityFix
Tue Nov 24, 2009 5:14 pm

RE:Opening Files[C Sharp]
-----------------------------------
God i feel like such a bugger. 

Another Question! 


 private void MinorMonsterBox2_Click(object sender, EventArgs e)
        {
            ListViewItem Temp = new ListViewItem(MinorMonsterBox2.SelectedItems.ToString());

            BattleList.Items.Add(Temp.SubItems.ToString());   // This is obviously wrong. 
        }


I basically want to transfer one listview item to another one on click. Which I kinda get (the clicking part) but I have no idea how to actually do the transfer properly >.>

-----------------------------------
rdrake
Tue Nov 24, 2009 5:35 pm

RE:Opening Files[C Sharp]
-----------------------------------
SelectedItems returns a collection of ListViewItems.

// Get the selected items.
ListViewItemCollection items = box1.SelectedItems;

// Remove them from the first box.
for (ListViewItem item in items)
{
    box1.Remove(item);
}

// Put them in the second.
for (ListViewItem item in items)
{
    box2.Add(item);
}Something like that.

-----------------------------------
RealityFix
Tue Nov 24, 2009 6:17 pm

RE:Opening Files[C Sharp]
-----------------------------------
I get the stuff after the ListViewItemCollection. But when i actually try to do ListViewItemCollection it doesn't exist. I looked through the list of suggestions it gives me but I can't seem to find anything that works >.>

-----------------------------------
rdrake
Tue Nov 24, 2009 7:30 pm

RE:Opening Files[C Sharp]
-----------------------------------
My bad.

ListView.ListViewItemCollection

-----------------------------------
RealityFix
Wed Nov 25, 2009 3:10 pm

RE:Opening Files[C Sharp]
-----------------------------------
Hmmm thanks but when i try to do 



ListView.ListViewItemCollection Items = MinorMonsterBox2.SelectedItems;



I get a error.

It tried:


ListView.ListViewItemCollection Items = new ListView.ListViewItemCollection(MinorMonsterBox2);
//ListView.ListViewItemCollection Items = new ListView.ListViewItemCollection(MinorMonsterBox2.SelectedItems --- This didn't work at all.)


and that didn't work the way i wanted.

-----------------------------------
rdrake
Wed Nov 25, 2009 3:32 pm

RE:Opening Files[C Sharp]
-----------------------------------
What's the error?

-----------------------------------
RealityFix
Wed Nov 25, 2009 4:00 pm

RE:Opening Files[C Sharp]
-----------------------------------
Error	1	Cannot implicitly convert type 'System.Windows.Forms.ListView.SelectedListViewItemCollection' to 'System.Windows.Forms.ListView.ListViewItemCollection'	C:\Documents and Settings\Owner\Desktop\DungeonsAndDragons2\DungeonsAndDragons2\DungeonsAndDragons\DungeonsAndDragons\DungeonsAndDragons\Form1.cs	366	53	DungeonsAndDragons


its a conversion error.

-----------------------------------
rdrake
Wed Nov 25, 2009 4:03 pm

RE:Opening Files[C Sharp]
-----------------------------------
Change my code to use that class then.

-----------------------------------
RealityFix
Wed Nov 25, 2009 4:50 pm

RE:Opening Files[C Sharp]
-----------------------------------
Im a crappy programmer if you haven't guessed. 



            ListView.ListViewItemCollection Items = new ListView.ListViewItemCollection(MinorMonsterBox2);
            BattleList.Items.Add(Items);


Best thing i could do to almost make it work?

Error:
Error	1	The best overloaded method match for 'System.Windows.Forms.ListView.ListViewItemCollection.Add(string)' has some invalid arguments	C:\Documents and Settings\Owner\Desktop\DungeonsAndDragons2\DungeonsAndDragons2\DungeonsAndDragons\DungeonsAndDragons\DungeonsAndDragons\Form1.cs	367	13	DungeonsAndDragons
