none
Adding a row to my datagrid when a user clicks a button.

    Question

  • I want to add a row to my DataGrid when a user clicks a button.  All of the examples I have seen thus far show how to bind data to the grid using ItemSource.  But in my case just as with many others, there are a lot of times when you need to be able to add content to the datagrid with out being forced to bind data.  Prior to the user clicking the button there are no rows in the grid thus there is nothing to add.   I can do this very easily with windows forms and AspNET how do I do this using WPF?  I am looking for a solution that does not require me to re-bind the data to grid using ItemSource.   The reason behind this is I have another page where the grid will be fed data from a multi threaded library.  It would be nice to just add data to the grid as it comes available from my threading manager.  In this situation the complete dataset will not be available immediately only a single record.  Waiting for the process to complete so I can use the Item source binding technique would force me to  wait 14 minutes until all threads have completed.  That would not be acceptable.  Is this possible with WPF?

    Monday, August 29, 2011 2:58 PM

Answers

  • I'm guessing at this but if the binding is bound to say a collection of employee, you would simply add a new employee instance to binding, there would be no values other than the default key which shouldn't be shown, but this should do it.  Remember that the datagrid must allow users to add rows.  In fact if you set that value in the datagrid properites, this is handled a gui layer, rather than at code behind for the datagrid. 

     


    JP
    • Marked as answer by hotshot Tuesday, August 30, 2011 12:13 AM
    Monday, August 29, 2011 3:27 PM

All replies

  • I did some further investigating is appears the only way to get data in the grid is by binding. The scenario I presented does not seem to exist.  Until someone shows me otherwise I will have to add my data to a collection and bind it to the grid when an item has been added to the collection.  I am using ObservableCollection to do this because you can get access to an event when an Item is being added to the colleciton.   If anyone has other ways of doing this I would be very interested.

    Monday, August 29, 2011 3:26 PM
  • I'm guessing at this but if the binding is bound to say a collection of employee, you would simply add a new employee instance to binding, there would be no values other than the default key which shouldn't be shown, but this should do it.  Remember that the datagrid must allow users to add rows.  In fact if you set that value in the datagrid properites, this is handled a gui layer, rather than at code behind for the datagrid. 

     


    JP
    • Marked as answer by hotshot Tuesday, August 30, 2011 12:13 AM
    Monday, August 29, 2011 3:27 PM