How to Bind a Label to the Count of a Datatable RRS feed

  • Question

  • I have built a Windows Form in VS2010, .NET 4. My project trolls through files, and when signifcant information is found, creates a row in a datatable. That all works fine.

    I would like to have a label on the form show the number of records in the datatable, as they are added to the table. I have had lots of fun connecting datagrids to datatables and textboxes to values in a column for the current record in a bindingsource, but this one eludes me when I thought it would be simpler. I think I know how to do this in code, but before I go down that track, I seem to feel this would be really easy in the designer. Is it possible?

    I've created a BindingSource object connected to the datatable, but I cannot seem to get other than row values by assigning the DataSource of the Label to the BindingSource. I want the count so that when the other thread is updating the table, my form will automatically update with it.

    Wednesday, September 12, 2012 7:13 AM


All replies

    • Proposed as answer by Chester Hong Monday, September 17, 2012 9:53 AM
    • Marked as answer by em-squared Monday, September 17, 2012 11:42 PM
    Wednesday, September 12, 2012 7:53 AM
  • Thanks for the response, Mitja, but it wasn't what I was looking for. I had asked if there was a way through the Designer because I had setup everthing else in my project that way and prefer to have all settings done in Designer, if possible (just for organisation sake). I had already started on writing code for an alternative as I suspected that there wasn't a way to do it. My solution wasn't using a wrapper, but I stopped and tried it, but it didn't work for me with a datatable (though it has an appropriate interface). I didn't want to fuss, so I went back to a simpler method and might try this again some day. Since yours is the only answer and indirectly answers my question, I'll mark it as the answer.

    Appreciate the quick response.

    Monday, September 17, 2012 11:42 PM