none
View contents from the list?

    Question

  • I have a list which contains list of id's. I want to be able to see all the id's from the list.
    I don't know if there is some kind of command i can use in Immediate Window or something else.
    Could someone tell me , how can i do it.

    P.S = Please don't recommend me to hover over list, click in eye glass and click in each '+' sign. I would also hate to create another method just to view the list.

    Any suggestions?

    creativity..
    Wednesday, August 12, 2009 1:36 PM

All replies

  • Hi,

    You can use Immediate Window for this. 
    ex. if you have list like,
    List<int> oList = new List<int>(new int[]{1, 2,3 ,4 });

    all you have to do is open Immediate Window, type oList and press enter.

    Hope this is what you are looking for!!!

    Regards,
    Vinil;
    Wednesday, August 12, 2009 1:55 PM
  • You can LINQ query your list into a dataset/table and load that result in a grid or suspend your code and visualize the results in a tabular format.
    Wednesday, August 12, 2009 2:14 PM
  • thanks guys..
    ^Vinil my list is something like this.

    pKey, id, flag
    1, 100, Y
    2, 200, N

    I am trying to view all the id from the list.

    ^michael cud you tell more abt what you suggested???

    creativity..
    Wednesday, August 12, 2009 2:18 PM
  • List<int> oList = new List<int>(new int[]{1, 2,3 ,4 });

    var query = from l in oList select l;

    You can now suspend in the debugger and open query and view results or bind query to a control on a form be it a listbox, grid...

    ListBox listBox1 = new ListBox();
    listbox1.DataSource = query;


    Wednesday, August 12, 2009 2:29 PM
  • Got this error:

    System.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSource.

    creativity..
    Wednesday, August 12, 2009 2:42 PM
  • The data bindings is asking for a source that implements the IList interface. Instead of a List use an ArrayList or a generic List<T> object.
    There are listboxes in C#. You can use a grid control also. You must put them on a form.

    In your forms class:

    DataGridView grid = new DataGridView();
    this .Controls.Add(grid);  // this is your form

    where you query th elist:

    grid.DataSource = query;
    Wednesday, August 12, 2009 2:55 PM
  • Hi,

    I think Sanjeev is looking for some view while debugging.
    If that is the case then adding Listbox and DataGridView is out of question.

    Another thing why do we need an additional LINQ on the List. I think List<T> implements IList<T>.

    Sanjeev,
    Can you give us few more details?

    1) What do you mean by list, is it really a "List" or what kind of collection object are you using?
    2) Can you give us code sample how do you add an item to your list?

    Regards,
    Vinil;
    Wednesday, August 12, 2009 3:51 PM
  • I have a list which contains list of id's. I want to be able to see all the id's from the list.
    I don't know if there is some kind of command i can use in Immediate Window or something else.
    PUt the I-bar of the cursor over the name of the variable after its loaded. While in the debugger do <Shift>-F9 to do a quick view of the values.

    William Wegerson (www.OmegaCoder.Com)
    Wednesday, August 12, 2009 3:52 PM
  • ^Vinil..you are rite abt ListBox and DataGridView.

    Ok here is what the list contains.

    public class EmployeeInfo
    {
    public int pkey     {get; set;}
    public int id          {get; set;}
    public string flag   {get; set;}

    }

    now the list contains list of EmployeeInfo objects.
    Once the list is populated, i want to be able to view ids from the EmployeeInfo object in the list.

    Hope this make sense?

    creativity..
    Wednesday, August 12, 2009 4:21 PM
  • In my first post I told him how to visualize it. The other option was if he wanted to display the results to a more readable window.
    Wednesday, August 12, 2009 5:29 PM
  • Hi,

    You might want to view these data in a datagridview as Michael suggested, please try the code below and adjust the postion of the datagridview for better view:
     EmployeeInfo e1=new EmployeeInfo();
                e1.pkey=1;
                e1.id=1;
                e1.flag="1";
                EmployeeInfo e2 = new EmployeeInfo();
              
                EmployeeInfo e3 = new EmployeeInfo();
               
                List<EmployeeInfo> list = new List<EmployeeInfo>();
                list.Add(e1);
                list.Add(e2);
                list.Add(e3);

                DataGridView dgv = new DataGridView();
                dgv.DataSource = list;

                this.Controls.Add(dgv);

    Harry


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, August 19, 2009 7:33 AM
  • Hi,

    If you do not want to click these '+', I think the only approach is pushing these data into a datagridview and or a listbox to show them.

    Harry

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, August 20, 2009 7:30 AM