Filling Listview & Imagelist selected item confusion c#
I new to programming and C# and seemed to have worked myself into a bit
muddle with the above. What i am trying to do is create a front end for
the living room media pc nothing to fancy to start with as i understand
this is a mamoth task for a total noobie like me. Ive flapped about and am
totally fine with launching external exe's,storing/loading resouces ect..
and been very happy with my results for my 2 week surfing.
So im starting off my project by just launching an emulator to start with
and what i would like to do is scan a folder for zip files and image files
and if it finds matching image and zip files it displays an image in a
list view for each zip found.
So i populate my listboxes like this and get my 2 listboxes showing the
stuff i want to see.
PopulateListBox(listBox1, "\\SomePath\\", "*.zip");
PopulateListBox(listBox2, "\\Images\\", "*.jpg");
private void PopulateListBox(ListBox lsb, string Folder, string FileType)
{
DirectoryInfo dinfo = new DirectoryInfo(Folder);
FileInfo[] Files = dinfo.GetFiles(FileType);
foreach (FileInfo file in Files)
{
lsb.Items.Add(file.Name);
}
}
So i now have my 2 listboxes and can see i have game1.zip and game1.jpg,
great now i can populate my listview with the game1 image and launch the
emulator he say's simple.
This is how i am currently populating the listview.
PopulateListView();
private void PopulateListView()
{
if (listBox1.Items.Contains("game1.zip"))
{
if (File.Exists("\\Images\\game1.jpg"))
{
imageList1.Images.Add(Image.FromFile("\\Images\\game1.jpg"));
listView1.Items.Add("", 0);
}
}
if (listBox1.Items.Contains("game2.zip"))
{
if (File.Exists("\\Images\\game2.jpg"))
{
imageList1.Images.Add(Image.FromFile("\\Images\\game2.jpg"));
listView1.Items.Add("", 1);
}
}
}
This is how i am currently launching and it works ok.
// launch item
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (listView1.Items[0].Selected == true)
{
string rom = "\\" + listBox1.Items[0].ToString();
// Launch code in here
}
if (listView1.Items[1].Selected == true)
{
string rom = "\\" + listBox1.Items[1].ToString();
// Launch code in here
}
}
So what the problem you may ask ? Instead of keep typing in all that info
for each item i want to use some kind of statment if possible and i dont
know what to search for which does not help. The image name will allways
match the zip name just need to loose the file extensions so to populate
the listview somthing like this.
if (listbox1 item = listbox2 item)
{
add to imagelist and listview automaticly with same index
}
Then i want to be able to launch just using somthing like this.
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
string rom = "\\" + listview.selected.item.tostring;
// Launch code in here
}
Hope im making sense im at my witts end.
Regards
Derek
No comments:
Post a Comment