IList-Items Retrieval

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dhivya1
    New Member
    • Feb 2008
    • 5

    #1

    IList-Items Retrieval

    How to retrieve items from Ilist in .net 2.0?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by dhivya1
    How to retrieve items from Ilist in .net 2.0?
    Have you checked the specs?

    Comment

    • Sameerlucky
      New Member
      • Feb 2008
      • 6

      #3
      Hi,

      I guess below example might b helpful to u..

      public static Dictionary DataSourceToDic tionary(object dataSource, string valueMember, string displayMember)
      {
      IList list = dataSource as IList;
      Dictionary listLookup = new Dictionary();
      if (list != null && list.Count > 0)
      {
      PropertyInfo valueMemberInfo = dataSource.GetT ype().GetGeneri cArguments()[0].GetProperty(va lueMember);
      PropertyInfo displayMemberIn fo = dataSource.GetT ype().GetGeneri cArguments()[0].GetProperty(di splayMember);
      foreach (object item in list)
      {
      listLookup.Add( valueMemberInfo .GetValue(item, null).ToString( ), displayMemberIn fo.GetValue(ite m, null).ToString( ));
      }
      }
      return listLookup;
      }

      Regards,
      Sameer

      Comment

      • dhivya1
        New Member
        • Feb 2008
        • 5

        #4
        Originally posted by r035198x
        Have you checked the specs?

        yes.IList doesnot have the Item Property using C#.net VS 2005.so how to retrieve each of the item ?

        Comment

        • dhivya1
          New Member
          • Feb 2008
          • 5

          #5
          Originally posted by Sameerlucky
          Hi,

          I guess below example might b helpful to u..

          public static Dictionary DataSourceToDic tionary(object dataSource, string valueMember, string displayMember)
          {
          IList list = dataSource as IList;
          Dictionary listLookup = new Dictionary();
          if (list != null && list.Count > 0)
          {
          PropertyInfo valueMemberInfo = dataSource.GetT ype().GetGeneri cArguments()[0].GetProperty(va lueMember);
          PropertyInfo displayMemberIn fo = dataSource.GetT ype().GetGeneri cArguments()[0].GetProperty(di splayMember);
          foreach (object item in list)
          {
          listLookup.Add( valueMemberInfo .GetValue(item, null).ToString( ), displayMemberIn fo.GetValue(ite m, null).ToString( ));
          }
          }
          return listLookup;
          }

          Regards,
          Sameer
          Thanks for the reply.when i try this code
          i am getting an error like this:

          "Using the generic type 'System.Collect ions.Generic.Di ctionary<TKey,T Value>' requires '2' type arguments " while building
          .

          I am new to Dictionary,pls let me know how to make a call this function with thes 3 parameters..
          Thanks in Advance

          Comment

          Working...