Click here to Skip to main content
15,914,066 members
Home / Discussions / C#
   

C#

 
AnswerRe: LINQ on un-typed IList collections? Pin
Not Active31-Mar-11 11:52
mentorNot Active31-Mar-11 11:52 
GeneralRe: LINQ on un-typed IList collections? Pin
SledgeHammer0131-Mar-11 12:05
SledgeHammer0131-Mar-11 12:05 
GeneralRe: LINQ on un-typed IList collections? Pin
Not Active31-Mar-11 12:12
mentorNot Active31-Mar-11 12:12 
AnswerRe: LINQ on un-typed IList collections? Pin
Keith Barrow31-Mar-11 12:19
professionalKeith Barrow31-Mar-11 12:19 
GeneralRe: LINQ on un-typed IList collections? Pin
SledgeHammer0131-Mar-11 12:53
SledgeHammer0131-Mar-11 12:53 
GeneralRe: LINQ on un-typed IList collections? Pin
DaveyM6931-Mar-11 23:51
professionalDaveyM6931-Mar-11 23:51 
GeneralRe: LINQ on un-typed IList collections? Pin
SledgeHammer011-Apr-11 4:45
SledgeHammer011-Apr-11 4:45 
GeneralRe: LINQ on un-typed IList collections? Pin
DaveyM691-Apr-11 10:34
professionalDaveyM691-Apr-11 10:34 
It often is!

For the sake of the thread... this could do with some more work, but using a generic ListViewItem class and the Cast method of Linq, something like this works.
C#
public class ListViewItem<T> : ListViewItem
{
    private T data;

    public T Data
    {
        get { return data; }
        set { data = value; }
    }

    public static IEnumerable<ListViewItem<T>> GetListViewSelectedItems(ListView listView)
    {
        return listView.SelectedItems.Cast<ListViewItem<T>>();
    }
}

C#
ListViewItem<string> itemA = new ListViewItem<string>();
itemA.Data = "a";
itemA.Text = "A";
ListViewItem<string> itemB = new ListViewItem<string>();
itemB.Data = "b";
itemB.Text = "B";
listView.Items.Add(itemA);
listView.Items.Add(itemB);

C#
IEnumerable<ListViewItem<string>> selectedItems = 
    ListViewItem<string>.GetListViewSelectedItems(listView);

Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



GeneralRe: LINQ on un-typed IList collections? Pin
SledgeHammer011-Apr-11 11:23
SledgeHammer011-Apr-11 11:23 
Questionhelp in vcd cutter Pin
gufranciit31-Mar-11 4:56
gufranciit31-Mar-11 4:56 
AnswerRe: help in vcd cutter Pin
Keith Barrow31-Mar-11 5:12
professionalKeith Barrow31-Mar-11 5:12 
AnswerRe: help in vcd cutter Pin
RaviRanjanKr6-Apr-11 19:19
professionalRaviRanjanKr6-Apr-11 19:19 
Questionhow to check how many messages are in sim memory Pin
aeman31-Mar-11 2:24
aeman31-Mar-11 2:24 
QuestionResponse large size data Pin
anishkannan31-Mar-11 1:14
anishkannan31-Mar-11 1:14 
AnswerRe: Response large size data Pin
#realJSOP31-Mar-11 1:38
professional#realJSOP31-Mar-11 1:38 
AnswerRepeat Pin
Not Active31-Mar-11 2:33
mentorNot Active31-Mar-11 2:33 
QuestionAppdomain [modified] Pin
abcurl31-Mar-11 0:35
abcurl31-Mar-11 0:35 
AnswerRe: Appdomain Pin
Rob Philpott31-Mar-11 1:31
Rob Philpott31-Mar-11 1:31 
QuestionProtecting from plugin crashes Pin
Benny_Lava30-Mar-11 22:37
Benny_Lava30-Mar-11 22:37 
AnswerRe: Protecting from plugin crashes Pin
BobJanova30-Mar-11 23:18
BobJanova30-Mar-11 23:18 
GeneralRe: Protecting from plugin crashes Pin
Benny_Lava31-Mar-11 1:13
Benny_Lava31-Mar-11 1:13 
AnswerRe: Protecting from plugin crashes Pin
Rob Philpott31-Mar-11 1:34
Rob Philpott31-Mar-11 1:34 
QuestionBlocking threads - growing memory Pin
GDavy30-Mar-11 20:48
GDavy30-Mar-11 20:48 
AnswerRe: Blocking threads - growing memory Pin
Eddy Vluggen31-Mar-11 0:38
professionalEddy Vluggen31-Mar-11 0:38 
QuestionCast Action<T> to Action<object> [modified] Pin
Adriaan Davel30-Mar-11 20:36
Adriaan Davel30-Mar-11 20:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.