User (Old forums)MemberApril 30, 2008 at 10:01 amPost count: 23064
It’s very frustrating having to ask such simple questions, but I search the forums thoroughly before asking each one. I’ve given up on the documentation and samples because the basics don’t seem to be covered without being buried under a mountain of code demonstrating advanced functionality and complex design.
Anyway, can someone point me in the direction of how to do simple row validation in code (not xaml). I’ve read that row validation isn’t supported, but that may be out of date because I’ve found a ValidationMode.RowEndingEdit property on the DataGridControl. If row validation really isn’t an option, cell validation is fine.
Either way, how do I gain access to the rows/cells and which events do I subscribe to?
Oh, and I’d prefer to do my validation without having to derive a class from DataGridControl. I’ve tried doing that already, and had some namespace problems. If that’s the only way to do it, so be it, but I would think there is an easier way to set up validation.
Imported from legacy forums. Posted by Mike Pateras (had 846 views)Xceed SupportMemberApril 30, 2008 at 10:15 amPost count: 5658
The ValidationMode property determines if cell content is validated when a cell exists edit mode or when a row does (by default, RowEndingEdit. I have corrected my working version of the documentation). That said, this property only applies when CellValidationRules have been provided to one or more columns (as demonstrated in example 1 in the Validating Data topic).
Version 2.0 does not provide any events such as EndingEdit that would allow you to validate using something other than cell-validation rules. The next version of the grid will have these events. What you could do if you require this sort of validation, is to derive from the DataRow class and override EndEdit to do your custom data validation before the edit process ends.
As for the documentation, I am very sorry that you did not find what you were looking for. Could you tell me what you would have liked to see/find? I try to be as thorough as possible when I write it; however, I think that sometimes I may be too involved in a project and would need to take a step back and look at it through the eyes of a user to get a better perspective. [:)]
Imported from legacy forums. Posted by Jenny [Xceed] (had 1307 views)User (Old forums)MemberApril 30, 2008 at 11:04 amPost count: 23064
Thank you for your response, Jenny.
I don’t think there is a problem with the documentation, except that is lacks a simple introduction to the basics. Maybe I am not familiar enough with data grids in general, but having worked with the .Net 2.0 grid and a different third party grid solution at work, I felt completely lost when I started in on the XCeed datagrid. However, once I saw some very simple examples, I was able to get up and running with it very quickly. It is very easy to use once you strip away all the complex stuff that (at least for now) I don’t need.
For example, it took me a while when I was just starting out to get the data into the grid. I searched the documentation and examples and went cross-eyed. Then I found out I just needed to do this:
List<MyObject> objects = GetObjectsFromDatabase(); // Get a list (or any IEnumerable container) of objects from any source
dataGridControl.ItemsSource = objects;
Done. This loaded everything up perfectly. Strings had a text editor that excapted any character, integers allowed only integers, and booleans had check lists. I was amazed when I saw that. I’d never seen a DataGrid (though again I have little experience with them) so easy to fill with data, especially one so feature rich.
I then ran into a problem inserting data into the grid. I found the answer I needed in the documentation, but it took me a while to get it up and running, but again the solution was simple:
BindingList<MyObject> objects = new BindingList<MyObject>(GetObjectsFromDatase());
objects.AllowEdit = true;
objects.AllowNew = true;
objects.AllowRemove = true;
dataGridControl.ItemsSource = new DataGridCollectionView(objects);
Again, done. That’s all it took and my items were getting added and properly constructed, and I’d even paved the way for editing and removing items as well.
So I guess i have no issue with the documentation, but the lack of simple samples to back it up. In fact, I think I may have given up on the docs a little too early, because as I said above they have proven quite useful in the past, and the CellValidationRule class contains the simple example I’ve desired:
public class ShippingCostValidationRule : CellValidationRule
public override ValidationResult Validate(
object value, CultureInfo cultureInfo,
object shipViaContent =
cellValidationContext.Cell.ParentRow.Cells[ "ShipVia" ].Content;
int shipVia = ( shipViaContent == null ) ? -1 : ( int )shipViaContent;
if( ( shipVia == 3 ) && ( Convert.ToDouble( value ) <
25 ) )
return new ValidationResult( false, "Freight must be greater than 25." );
return new ValidationResult(
true, null );
It seems all I need to do is derive my validation rule and add it to the collection. Perfect.
And I should point out that the docs are rather thorough and well-worded. So I should apologize, I suppose I was just frustrated because it seems like I was consistently trying to sort through SolidFoundation which is somewhat huge and complex for the simple concepts that I'm trying to get acclimated with, and I lumped all of documentation in with that frustration.
So as far as what I'd like to see is a sample covering the topics that I've learned in the past couple of days. With as easy as the XCeed WPF DataGrid is to work with, simple code samples are all that is necessary for a beginner such as myself to really get rolling with this terrific tool. All of the following I was able to get together with only about 100 lines of code:
Loading data into the grid
Adding new items
Saving updates to a database
Wiring up a combo box column to allow the data to select from user friendly text that stores (and loads from) a different value in the database
Wiring up a button column with an attached click event
I think it would make life a lot easier for the XCeed beginner if a simple sample existed that demonstrated this basic functionality. It would be nice if there was an example in xaml and an example in code. I guess I don’t really understand how to really leverage xaml, because honestly I’d rather be writing in code. I think it is a great tool for designer work, but for doing anything besides setting up a single instance of a control and its properties I’d really rather be working in C#.
Anyway, thank you again, Jenny, for all of your help. I really do think the documentation is well written, and I appreciate you handling my frustration with patience and an open mind. I just get bothered because often times I’m looking for a “Hello World” example and I have to sift through very complex code to try to figure out what’s going on (MSDN is terrible about that, I feel, but maybe this is just a personal frustration that not many share).
And thanks again for making such a great tool as the DataGrid available (and for free, no less). It really has been a joy to work with once I’ve figured out the basics.
And now to write my validation rules.
And here’s a clear example of the things I really like about the docs:
Through the use of validation rules, the content of any cell can be
validated before it is committed. Validation rules can be provided for
all the cells in a column by adding one or more CellValidationRule objects to a column’s CellValidationRules collection, or they can be provided on a cell-by-cell basis through cell’s CellValidationRules
collection. By default, if the end-user input does not pass the
validation process, the focus will remain in the cell whose value
failed the validation process until the new value passes the validation
rules or the escape key is pressed to cancel the modification.
Clearly worded, easily understood, and covering a great deal of information. Much better than MSDN and other sources of documentation I’ve read.
Imported from legacy forums. Posted by Mike Pateras (had 1632 views)Xceed SupportMemberApril 30, 2008 at 11:50 amPost count: 5658
Thank you for your kind words and feedback [:)]. I think I understand what you are saying and have an idea as to how to simplify the task of getting started with the grid, or at least take a more step-by-step approach of migrating from a C# WinForms way of thinking to a WPF one. Something along the lines of demonstrating what a user coming from a C# WinForms environment would normally try first with the grid with examples of how to do it, and then moving on to what is recommended in WPF.
Is this something that would have helped you get started with the grid?
Imported from legacy forums. Posted by Jenny [Xceed] (had 336 views)
- You must be logged in to reply to this topic.