0

What is the WPF control I need if I want the user to be able to input Cross Ccy amounts, ie the data needed for each row is

Ccy One, Ccy Two, Amount

I want a grid-like control where the User can enter data for each cell in the row and once you begin to enter data in the cells, a new row gets added underneath, so the control keeps growing with every entry the user inputs and has no upper limit but grows to fit, using a scrollbar when it goes outside the bounds of the grid container.

Is there a built in control to do this? Or do I have to add functionality to listview/datagrid?

0

2 Answers 2

1

If you want the user to be able to add new rows just set the CanUserAddRows property on the DataGrid to true.

<DataGrid CanUserAddRows="True" ..../>

If you want rows the be added when the user edits a data in a cell in an existing row, you can register to one of the cell edit events (depending when you want the new row to be added) and add rows to the grid or items to the collection it is binded to.

datagrid.CellEditEnding += (grid, args) =>
{
      datagrid.Items.Add( ....);
};
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks veyr much. Ive got that working now, though what I would like is to bind each row of the datagrid to a ViewModel object, call it CcyCorrelationViewModel. I've bound the ItemsSource to an observable collection of type CcyCorrelationViewModel but when you add a row, the text clears out of each cell as you tab off it and you end up with a blank 1st row, even though a 2nd row gets added, and the underlying VM object doesn't get any data in it. How do I bind each of the columns of the grid to a property in the viewmodel?
@user1122909 For my understanding CcyCorrelation is a Model, not a ViewModel. So you should have an ObservableCollection of type CcyCorrelation in your ViewModel. Now, binding column in your grid to propertis of CcyCorrelation is pretty straight forward. Suppose CcyCorrelation class contains a property called Amount, the just bind the column to that property <DataGridTextColumn Binding="{Binding Amount}"/>. If you are having difficulties doing that edit your question with your code and we'll try to help you :)
Thanks, that's perfect. Good point about the Model/VM, I think I am falling into the habit of calling everything a ViewModel when in fact they are just Models. Think I need to do a bit more reading to clarify the best design practices
0

this is the standard behavior of a datagrid, if the property CanUserAddRows is set to True

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.