This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi Jason, I've to create a dynamic datagrid and I would like to use your datagrid because of the functionalities. But in my case I don't know exactly the number of columns that I need. I only know the exactly number after reading a file. So, the creation of my datagrid has to be in code behind. I've a lot of doubts !!!! How can I create bindings to each column? How can I put a column with an checkBox ? How can I get the event when the users click on a checkBox? I'm thinking to use your datagrid with an observable collection. And in this datagrid, I need to delete, insert and edit values too. I look your Mindscape sample, but I didn't find anything like that. What is the best way to do this? I'm completly lost.... Do you have any example to help me? Best regards, Raphaela. |
|
|
Hello Raphaela To use dynamic data in the DataGrid, there are 2 main options - You could either use a DataTable/DataView as the items source, or you could use an observable collection of a class that extends ICustomTypeDescriptor. I would recommend starting with trying the DataTable/DataView approach. The best way to do this is to create a DataTable, and then bind the ItemsSource of the DataGrid to the DefaultView property of the table. When you create the columns yourself, you bind them up to the data by setting the DataGridColumn.PropertyName property. This simply tells the column the name (or binding path) of the property on the data objects. In the case of using a DataTable/DataView, you set the PropertyName to be the same name of the appropriate DataColumn that you setup in the DataTable. Displaying content within each cell is split into 2 parts: a display template, and an editor template. You can set the DisplayTemplate or/and EditorTemplate properties of each DataGridColumn if you want to customize the way cells are displayed or/and edited. For checkboxes, you'd generally want both the display and edit templates to be a CheckBox, so you can set both these properties to be the same template. In your template, you simply have a CheckBox that binds to the appropriate data. In the case of using a DataTable/DataView, the binding will look like this:
(Where 'n' is the index of the column in your table that you want to bind to). Listening to when the check box is clicked may be different depending on what you want to do. Generally it is best to listen to changes in the model. To do this using a DataTable, you can attach an event handle to DataTable.DefaultView.ListChanged. The event arguments will give you the index of the row that was changed. Note that this event occurs for all types of changes such as additions and deletions as well. Editing values is fully supported by the DataGrid. You can also set the AllowUserToAddRows property to true which will display an empty row under all the data that the user can use to add new items to the data grid. Deletions, row relocations and adding rows to arbitrary positions is not yet supported by the UI. You can easily update the model to do these things though. See how far you can get with these suggestions and let me know if you have further questions. -Jason Fauchelle |
|