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 There, We have a few questions about the DataGrid: 1) We have type converter to convert the enum value to a nice user-friendly string value, Everything works fine until you trying to change the value from the dropdown property. The function ConvertFrom on the coverter is never called and it crashes at ConvertTo functions. And same kind code works for the WinForms' DataGridView. 2) The selectionType of the datagrid is too limited, once you choose Row, the whole row is selected and if you choose cell type, the cell is selected no matter you click on cell or row header. When I click on row Header I want it to select whole row and when I click on cell the cell is selected not the whole row. So Can you add the third choice "Row or Cell" to meet our needs? 3) The SelectedItems is not bindable, so We can not put it into our view model. We also does not have SelectedItemsChanged Event for us to manipulate. So how are we going to set the SelectedItems in our View Model? 4) For the comboBox item, you need to click on 3 times to have a dropdown, Can we make it only click on twice? 5) SelectedItem cannot do a two way binding? Thanks a lot, Gordon |
|
|
Hello Gordon 1) I have not been able to reproduce this crash. Here is an enum converter that I used to display user-friendly strings in an enum combo box. Look through this code and see if anything stands out that you may have missed.
The enum is called CitizenshipStatus and the converter simply puts a space in "Worker Visa". It is normal for the ConvertFrom method to never be called. The items in the combo box are the enum values, the converter simply displays them appropriately. If you can't get it to work, please send us a repro or the code for your converter and we will see if there is some functionality we have overlooked in the data grid. 2) I have added the RowAndCell selection type. Simply set the DataGrid.SelectionType to be DataGridSelectionType.RowAndCell, then the user can select rows by clicking on the row headers, and select cells in the usual way. This selection type supports all the selection modes. (single, multiple and extended). In single mode, only 1 row OR 1 cell can be selected at one time. Either the SelectedCell property or the SelectedItem property will be set as appropriate, the other property will be set to null. This will be available in the next nightly builds. 3) You can cast SelectedItems or SelectedCells into an INotifyCollectionChanged to get collection changed notifications. Let me know if this solution is not going to work for you. 4) I have added a DataGrid.CellEditModeBehaviour property. By default, this will be OnClickHighlightedCell. You can set this to DataGridCellEditModeBehaviour.OnClick which will allow cells to go into edit mode on a single mouse click. This means that only 2 clicks will be needed to open a combo box drop down. This property will be available in the next nightly build. 5) SelectedItem does support two way bindings. Make sure the property you are binding to can raise property changed notifications. Please let us know how this goes or if you have further questions. -Jason |
|
|
Thanks a lot, Jason. First, I don't understand your solution on #3). In the datagrid, If I derive a class from your datagrid, how do I overwrite a function or fire up event that when selection is changed, then I can cast SelectedItems to collection that it is a dependecy property in derived class. And then I can bind a viewmodel property to this property. Since in my view model I don't want to know anything about the View. If you are talking about different thing, could you please elaborate a bit more? 5)the problem is that when I change the selection, say from row1 to row2 the SelectedItem does not update the property of my viewmodel that it bind to. again, If I have SelectionChanged event or function OnSelectionChanged to override then It will solve my problem. Does it support OneWayToSource binding? Can you add something for datagrid say AllowUserAddRow, so we don't need to change the datasource for the new row? Thanks a lot |
|
|
Hello Gordon 3) Somewhere in your application, cast the SelectedItems collection into an INotifyCollectionChanged. On the INotifyCollectionChanged, you can subscribe to the CollectionChanged event. This event will be raised whenever an item is selected or deselected. You can use the same technique for the SelectedCells collection if you need to listen to when cells are selected and deselected. This will be something like the following:
Where dg is the DataGrid. Then the event handler would be like this:
You could either do this in the application code behind, or extend the data grid to put the logic in there. Let me know if you need further information about this. 5) I am able to get a two way binding to this property working properly. We must be setting things up differently. Could you please send a sample that demonstrates that this is not working, then I'll be able to solve this issue for you. For the AllowUserAddRow feature, I should be able to add this for you. Could you please give some more information and details about the behaviour that you expect it to have. Please describe what the user should do to add a new row. There are several ways this could be done. -Jason |
|
|
Thanks Jason, 1) When I changed to RowAndCell, it worked but there are other problems, for example: We do not know which cell it focused on, so we don't know which item we are focused on(when we are on different record it behavious different for rest of the UI), if we can have something like currentItem property, so we can bind our view model property to that. even you give me the current cell property or cellEnter, cellLeave events, it would be nice. 2) About AllowUserAddRow property, we just want to have an "empty" row that user can input data, when the user finish the new row (by clicking on other row/cell or enter ) a new "empty" row is there again for new data, just like DataGridView in Winform. 3) We are just wondering, the Nightly build with new feature, will it be in Commecial Nightly Build too if we buy the products? At which point you will going to put all these small fixes into a formal release? We love your support. Gordon |
|
|
Hello Gordon 1) The SelectedItem property gets the object corresponding to the currently selected row. The SelectedCell property will give you a DataGridCell model object of the cell that is currently selected. And also the HighlightedCell property gets you the DataGridCell model for the highlighted cell. The highlighted cell is the cell that has the block box around it or the cell that is being edited. When you have a DataGridCell model object, you can use its Value property to get the object displayed in that cell. All these 3 properties are dependency properties which you can bind to. Let me know if this is what you were looking for. 2) Thanks for this description, I'll look into adding this feature over the next few days and let you know when it's available. 3) All modifications we make are available in both the trial and commercial nightly builds. We don't have a particular scheduled day for when the next major version will be. Thanks for all your feedback! -Jason |
|
|
Thanks Jason. 1) We tries to implement everything in MVVM in this project, and one of the rules is ViewModel will have no idea about the View. So they just not want DataGridCell appears in the ViewModel. So if we can use an event or overwrite a function to get the currentcell, then we can get the value of the cell or rowcontent of the cell. from this we can construct a current record. Right now I am using the ValidateCell event to get the CurrentRecord. But I don't think it is a very good idea to use ValidateCell. So if we have other event or function to do that it would be better. Or you from the code behind use SelectedCell, highlightedcell or SelectedItem to give me CurrentItem, then I just need to bind it to your currentitem, it will be perfect. 2) When you implementing this, could you expose the event overidable function like OnAddNew(...) Here is some new questions: 3)Can we have access to the row header, for example, we want set the count number in the row header? 4)How do we get rid of the last empty column? 5) Column Width is double value, can we have Column width as GridLength so that we can set the width as weight, or can you give us something FillWeight? 6) Can we change the the cell background on run time, for example, on the cell of diagonal we want to change to grey and the value cannot be editable. 7) Can we set the individual cell to be ineditable? Thanks, Gordon |
|
|
Hello Gordon 4) To get rid of the last empty column, do you mean for the last column of data to fill the remaining space? 6 & 7) You can disable editing for a particular cell. This is done by using the DataGrid.SetAllowEditing method. You can use the method overload that takes in a DataGridCell model object. To get a DataGridCell object to pass in, you could either instantiate one yourself by passing in the row data and column object into the constructor, Or you can use the DataGrid.GetCell method which will return a DataGridCell for the given row and column indices. At the moment you can not change the background color of a particular cell. I'll look into adding this feature. I'll keep working on the remaining items here. Jason Fauchelle |
|
|
Thanks Jason. 4) Yes |
|
|
Hello Gordon The user-add-row feature is finished and will be available in the next nightly build. I have mostly followed the API and functionality similar to the WinForms DataGridView. Try it out and let me know if there are more details or options that you need for this feature. To enable this feature, set the AllowUserToAddRows property to true. An empty row appears at the bottom of the data. When the user starts editing this row, it will be added to the items source, and a new empty row will appear - just like how WinForms works. When the new data object is added to the items source, the UserAddedRow event is raised. There is also an OnUserAddedRow method that you can override. Note that this feature only works for data that has a default constructor. Let me know if you need support for data objects that have internal or parameterized constructors. Jason Fauchelle |
|
|
Hi Jason, 1) The addnewrow is working. Thank you very much! 2) But the refresh problem for BindingList as ItemsSource is still the problem. 3) Your DataGrid does not take the System.Data.DataTable as the ItemsSource, please make it work with DataTable for us. Gordon |
|
|
Hello Gordon Good to hear that the add-new-row is working well for you. In the same nightly build (the one you have already downloaded) you will also find the SelectedData property. The SelectedData property will be the content of a row when a row is selected, or the data value within a cell if a cell is selected. I think this is what you were looking to bind to. Let me know if the SelectedData property is not quite what you needed. I should also let you know that DataGridCell objects are model objects meaning that it's fine to bind them into your view models if necessary. I'll look to see if we can add DataTable support soon. Jason Fauchelle |
|
|
Hi Jason, Thanks a lot for looking into this. We really appreciate you and your colleagues' effort to resolve issues. Thanks for pointing out the SelectedData info here. It may not be exactly what we are looking for, here is the explanation: 1) If we use SelectType as "Cell" Or "RowOrCell", the SelectedItem is null, so binding to this won't help 2) Now you added SelectedData, which is cool. But when I am in one cell of first row the SelectedData is the Cell Value, I still want to know which Row I was in, so I can change the UI which related to this row's infomation. Now I click on one cell on 2nd Row, again the SelectedItem is null, the SelectedData is the cell value, I have no idea what row data I am in and What kind UI I should change to. The testing project I sent to you related to thread http://www.mindscapehq.com/forums/thread/299274#301648 shows what I mean I need to change the UI according to the current selection (in there I use SelecteType="Row" so the SelectedItem is not null) If you can give us something like: CurrentItem, which probably very easy for you to add now, No matter if we choose cell or a row, it is the current record. I.e. when the SelectedItem is not null, CurrentItem will be SelectedItem. If the SelectedData is cell value CurrentItem will be the value of the row containing the cell. I know I give you a lot of headache on support issues, but I am thinking it makes your products and our products better if we solve all these problem. DataTable is very important to us though. Thanks, Gordon. |
|
|
Hello Gordon Thanks for the explanation for this, I know what to provide now. Thank you for all the questions and feature requests, these have greatly helped us improve the quality of the Charting and DataGrid controls! Every suggestion is helpful and it's great to see developers give them a good run! :-) We'll try get DataTable supported throughout next week. Jason Fauchelle |
|
|
Hello Gordon The DataGrid now supports DataTable as the ItemsSource! This is available for download right now through the currently nightly build: http://assets.mindscape.co.nz/Trial/Nightlies/20120327/WpfElements5Trial-20120327.msi Here's how to use it: If you are setting the ItemsSource in C#, you'll need to set the ItemsSource to be a new DataTableWrapper and pass in the DataTable in the constructor. If you are setting the ItemsSource with a binding, you can use the DataGridItemsSourceConverter which will conveniently create the DataTableWrapper for you. This is behaving nicely with all the existing features including sorting, grouping, column reordering and dynamic data updates. Let us know if we've missed any details. Jason Fauchelle |
|
|
Thanks a lot, Jason. I cannot wait to use it. I am taking a week off and I will test it out the first thing next Monday when I get back. Gordon |
|
|
Hi Jason, We have a small problem on the DataGrid's DataTable. One of our data table has a readonly column (GUID), so it crashed and says the readonly field cannot be using TwoWay binding or OneWayToSource Binding. So I turned off the AutoGenerateColumn, but the things in the ItemsSourceChanged Event I want to generate the column in the code, but I have no access to the DataTable from DataTableWrapper, So I cannot get the column info from the DataTableWrapper. So I am wondering, If you can put a property "DataTable" or "DataView" on class DataTableWrapper, so we can manipulate the columns on the run time? Thanks Gordon |
|
|
Hello Gordon The next nightly build will include a DataTable property on the DataTableWrapper. I've also made the DataGrid automatically use read-only cells for read-only columns in the DataTable. Jason Fauchelle |
|
|
Hello Gordon The next nightly build will also include a HighlightedItem property. This property contains the content object of the row containing the highlighted cell. So in row mode, this will be the selected row content, in cell mode, this will be the content of the row that contains the selected cell. I've also included a RowHeaderTemplate property which lets you customize the row headers. You could use this to display row numbers in the row headers. To do this, you would use a template like this:
This data template simply contains a TextBlock used to display the row number. The Text property uses an AncestorType binding to get the Index property of the data grid row. I've also included our ArithmeticConverter to make the row numbering start from 1 (since the Index property starts from 0). Then you can use this template to set the RowHeaderTemplate property on the data grid. Let us know how these go. We are now working on being able to set the width of columns to be a fill-weight. Jason Fauchelle |
|
|
Hi Jason, 1) The DataTable is now working. 2) HighlightedItem is readonly property so I cannot binding in the xaml. I understand that it is readonly property, but could you add an event like HightedChanged or overridable function OnHightedChanged so we can manipulate it ourself and make it bindable in xaml? 3) RowHeaderTemplate works for numbers, I presume it will work for any other custom header. |
|
|
Hello Gordon 2) My apologies for missing out the event. The next nightly build will include the HighlightedItemChanged event as well as an OnHighlightedItemChanged overridable function. 3) Yes, you can create any custom row header content you want by using the RowHeaderTemplate. Jason Fauchelle |
|
|
Hello Jason, As far as I have seen, Mindscape's datagrid is very fast. I would like to use it. But I have trouble binding it to a datatable. Have to say, that I'm using VB and not C, and most examples are in C. Do you have a simple VB sample, that I can understand how to create the class for the DataTableWrapper ? Have a nice day Dave |
|
|
Hello Dave I have attached a sample that demonstrates how to bind the ItemsSource of our data grid to a DataTable in VB. To run this sample, you'll need to include a reference to the Mindscape.WpfElements.dll. The main trick is to make sure you're using the DataGridItemsSourceConverter in xaml like this:
The converter is important because the ItemsSource property expects an IEnumerable which means a DataTable is not compatible. That is what the DataTableWrapper is for which the converter will create for you. Let us know if you have any questions about this. Jason Fauchelle |
|
|
Hi Jason, We have another problem with datagrid: 1) If a column is binding to the data with type double, then in the datagrid when enter value as .98, it will show 0.89. The problem is when we enter .9 it automatically changed to 0.9 with the cursor still in position after decimal point. 2) We really want to be able to change the color of individual cell, row and column and disable individual cell, row and column. But currently we cannot do that. Is that possible for you to add them? Thanks Gordon |
|
|
Hello Gordon 1) I have not been able to reproduce this issue. Could you please let us know a little more information about your set up such as which theme you are using and if you are applying any custom EditorTemplate or TypeEditor to the column. 2) You can disable an individual cell by using the SetAllowEditing method on the DataGrid. Pass in the DataGridCell model that you want to disable, and also pass in false. There are two ways to get a DataGridCell model object. a) Create a new DataGridCell instance by passing the row content object and the DataGridColumn into the constructor. b) Use the DataGrid.GetCell method which takes in a row and column index. To disable a row, you can use the DataGrid.SetAllowEditing property and pass in the content object of the row you want to disable. To disable a column you can simply set the AllowEditing property to false on the DataGridColumn. At the moment we don't provide a way to change the background color of a cell, row or column. Would a similar API as disabling these parts work for you? (eg. SetBackground methods for row&cell, and Background property for columns). If you have suggestions for an alternate API for this we'll see what we can do. Jason Fauchelle |
|
|
Thanks Jason The other developer in our team make the changes on Disable Cells and it works. Sorry I did not follow it up. Next time I will do a better job for follwing it up. Could you implement the app SetBackground the same way as in SetAllowEditing()? Thanks Gordon |
|
|
No worries Gordon I've implemented the background setters which will be available through the next nightly build. On the DataGrid there will be the SetCellBackground and SetRowBackground methods. DataGridColumns will now have a Background property. Regards Jason Fauchelle |
|