I have a datatable im trying to set as the source of listbox but only get System.Data.DataRow in place of my records i want to see in the list


  • i have a datatable that is returning 3 records from my table. That works..

    I list a listbox on my WPF application that i want to display those records.. but when the app loads, it just displays:

    "System.Data.DataRow" 3 times i know that its returning the correct number because i can add or remove and the list displays the correct number of records, but i cant seem to get the actual data i want to display in the list.. below is my datatable code i have in my db.cs file..

            public DataTable getList(int ID)
                DataTable dtList = new DataTable();
                NpgsqlConnection conn = new NpgsqlConnection(_dbConn);
                NpgsqlCommand command = new NpgsqlCommand("select * FROM case, info WHERE = AND = " + ID + ";", conn);
                    if (conn.State != ConnectionState.Open)
                    NpgsqlDataAdapter npgData = new NpgsqlDataAdapter(command);
                return dtList;

    Then within my window_loaded event i have this code to set the listbox.

                DataTable dtList = dac.getList(2);
                lbList.ItemsSource = dtList.AsEnumerable();

    Friday, March 23, 2012 8:47 PM


All replies

  • You need a DataTemplate. Please read

    Good luck!

    noorbakhsh حميد نوربخش

    • Edited by noorbakhsh Friday, March 23, 2012 9:10 PM
    • Marked as answer by Cubangt Saturday, March 24, 2012 2:42 AM
    Friday, March 23, 2012 8:51 PM
  • i got it working but not as i need it..

    i changed the line for the ItemsSource to this and that works and displays the names, i selected two columns in my statement to join them so they i can display the first and lastname but when i do that it doesnt display.. when i debug it, the value returns is the combined names..

    what am i missing.. the column being returned in the select statement is called fullName

    lbList.ItemsSource = ((IListSource)dtList).GetList();
    lbList.DisplayMemberPath = "firstname";

    If i replace firstname with the fullname nothind shows up..
    Saturday, March 24, 2012 2:15 AM
  • You are missing a DataTemplate as I mentioned in my first post. I guess you can use "fullName" in DisplayMemberPath to show them.

    noorbakhsh حميد نوربخش

    • Edited by noorbakhsh Saturday, March 24, 2012 2:22 AM
    • Marked as answer by Cubangt Saturday, March 24, 2012 2:42 AM
    Saturday, March 24, 2012 2:21 AM
  • thats the problem, i cant use it in the displaymemberpath..

    i can use all my column names, except that one.. i can display lastname, city, state and so on but using fullname doesnt work..

    Saturday, March 24, 2012 2:33 AM
  • thanks.. i think i figured it out.. i was using the datatemplate, but had my binding wrong, atleast i think..

    i redid the datatemplate to have just a textblock and bind it to the fullname column and it works.

    Saturday, March 24, 2012 2:42 AM