Hi Mike,
My apologies for the delayed response. Let me re-state the problem for
better understanding of its solution:
The problem:
The application UI has a List View control and a Text Box and a Button. The
list view displays a list of files with checkboxes besides each file name.
If the user wants to modify the names of certain files, he selects those
files [by checking the corresponding checkboxes] , enters some text in the
text box and then clicks on the button. Now your application should update
all the checked file names with the text in the text box.
The solution:
Let's make certain things clear before i show you the sample code.
1. The ListView.CheckedItems property returns a
CheckedListViewItemCollection.
2. Each object in the collection is a ListViewItem and not a string.
For more info on this see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewclasstopic.asp
3. The filename of [let's say] the first file in the list is the text
property of the first item in the list view. Hence it should be accessed as
ListViewItem.Text
For more info on this
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewclasstopic.asp
Hence to loop through the items in the collection and update the filename,
you should use something like this:
Sample code:
//get all the checked items in the list
ListView.CheckedListViewItemCollection checkedItems =
this.lvMassFileConversion.CheckedItems;
//for each checked item
foreach ( ListViewItem myItem in checkedItems )
{
//get the new filename
string myFileName = this.txtBoxNameConvsersion.Text + "-" +
myItem.Text;
// do your file name updation here. Remember, myItem.Text gives you
the filename [myItem given you the entire list view item]
}
To understand more about what a list view control is and how it behaves, you
can look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewclasstopic.asp
and
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listview/listview_overview.asp
or you can search msdn for a 'listview control'
Thanks,
Devi JV [MSFT]
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm [quoted text, click to view] "MikeY" <mikesinfo@yahoo.c> wrote in message
news:CX%Sd.13174$uO.479711@news20.bellglobal.com...
> Hi Devi,
>
> I was thinking after I posted my question that I might not of gotten the
> point across.
>
> My application pulls all my files *.txt, *.mp3, etc from a folder. Where
> it
> is displayed with in my ListView (lvMassFileConversion), with checkboxs.
> From there the user is able to check-mark the required checkbox's in order
> to change their names of the files(append). This happens when the user
> then
> inputs a new name with in a textbox (txtBoxNameConvsersion) and clicks the
> conversion button. The checked files then are all renamed (appended). All
> the syntax happens with in the Conversion button function. This all takes
> place at run-time.
>
> The syntax that I previously posted (but forgot to mention) is the syntax
> from when I use the CheckListBox. Now this works just fine (using the
> CheckListBox) and I am able to get the exact results that I want, using
> the
> same scenario. But I don't want to use the CheckListBox, because of
> previously posted reasons, size, etc. The code I posted was me trying to
> modify the syntax to use with my ListView instead, but did not work.
>
> Thanks for the links, but didn't see what I was looking for.
>
> Hopefully I am making more sense over my morning coffee. Any & all help is
> appreciated.
> MikeY
>
>
> "Devi JV [MSFT]" <devijv@online.microsoft.com> wrote in message
> news:utAhsjZGFHA.4004@tk2msftngp13.phx.gbl...
>> Hi Mike,
>>
>> I understand that you are using a list view control with checkboxes
> besides
>> each item in the list. But i am unable to get what the exactl problem is.
> Do
>> you want the user to be able to edit the items at run time [OR] do you
> want
>> to change the contents of the list programatically?
>>
>> User editing scenario: The list-view supports in-place editing of its
> items.
>> Just set the LabelEdit property to true. Look at
>>
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewclasslabeledittopic.asp
>> for more info.
>> Programatic updations: You can use the ListView_SetItemText(iItemNumber,
>> iSubItemNumber, blah,blah) macro to set/reset the item and sub-item
>> texts.
>> To update the item contents, set the iSubItemNumber to zero. Look at
>>
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listview/macros/listview_setitemtext.asp
>> for more info.
>>
>> If this is not what you want, please write back explaining the issue.
>>
>> Thanks,
>> Devi J V [MSFT]
>>
>>
>> --
>> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>>
>>
>> "MikeY" <mikesinfo@yahoo.c> wrote in message
>> news:wGSSd.10761$uO.445559@news20.bellglobal.com...
>> > Hopefully someone can help me on this.
>> >
>> > I am using C#, making Windows forms.
>> >
>> > I have created a listView with checkbox's. I have enabled the
>> > checkboxes
>> > under the properties, and all the data, checkbox's and icons are
> displayed
>> > as they are meant to be. My problem is this, I am trying to achieve the
>> > same
>> > results as I get with CheckListBox(s), where I am able to select
>> > (Check-mark) various checkboxs items and able to alter the data. I do
>> > prefer
>> > to use ListView because of adding icons, view properties, sizing, etc.
>> >
>> > A sample of my code is below where I am trying to grab my selected
>> > (checked)
>> > items then convert the name with my inputted text name:
>> >
>> > foreach(string myItem in this.lvMassFileConversion.CheckedItems)
>> > {
>> > string myItem2 = this.txtBoxNameConvsersion.Test + " - " + myItem;
>> > //Over-write old file with new file
>> >
>> >
> File.Move(Path.Combine(currentFolderPath.myItem).Path.Combine(currentFolderP
>> > ath.myItme2)
>> > }
>> >
>> > Now I can achieve the required results with checklistbox, but because
>> > of
>> > the
>> > above mentioned I'd like to stay with listview.
>> >
>> > Thank you all in advance.
>> >
>> > MikeY
>> >
>> >
>>
>>
>
>