I have a DataGrid (dataGrid1) where records can be added and deleted.
Based on that dataGrid1, I want to make a new Grid with buttons in it based on ID and Types’. Cols will also have to given a DataSource of add dynamically, but that will be just while generating for the 1st time in Window_Loaded itself. Rows can be added/removed based on changes in dataGrid1. I want somethign like this :

On each Btn click, a new window will be opened for entry of the particular Type and for the particular ID. If the details are already entered, then the text of btn wil be “Update” else “Add”.
What could be the best resource/control to perform this operations ? At present, I just did a Grid with 2 stable cols. Any ideas for the above to use Grid, DataGrid or something else. And adding/removing rows will be easy in which way and how.
Any help is appreciated.
Okay, let me try to take an example which is similar to your needs
Let’s assume we use this class:
And we are willing to display a
DataGridlisting the ID, and having as a second column aButton, with the propertyMyStringas content, which, when clicked, launches theICommandMyCommandwhich opens in a new window whatever you want.Here is what you should have on the View side:
This will show a
DataGridtaking all the content in anIEnumerable<MyObject>named ‘MyList’, and shows two columns as defined before.Now if you need to define the command.
First, I recommend you read this introductory link to MVVM and take the
RelayCommandclass (that’s what we’re gonna use for your problem)So, in your
ViewModel, the one which defines theMyList, here is how you should define some of the useful objects:This should be enough to create whatever you want. As you can see, every
Buttonwill call a method (ShowWindow) which is defined to show your new window, do whatever you need inside. TheRelayCommandis actually just here, as its name says, to relay the command fired by the button to a method which contains the execution logic.And… I think that’s all you need. Sorry for the late answer BTW
EDIT – generating columns manually/dynamically
The following code is part of a code I had to do when I had a similar problem.
My problem was, I needed to change the columns displayed every time a
ComboBox‘sSelectedItemwould change. So I put this in aSelectionChangedevent handler.I don’t know where exactly do you need to generate your columns, but I’ll give you a general example.
Assume your
ItemsSourceis anObservableCollection<MyNewObject>MyNewObjectis the following:You should put somewhere in your code (should be when you need to generate the column) the following code, which is generating a number of columns equal to the length of the first
MyNewObjectfrom the list (note: this is in code-behind, and theDataGridyou’re working on is named dataGrid)This will create one column for each string found in the first object. Then, enhance it with whatever command or display trick you need!