Hi,
I've used XamDataGrid with 4 unbound columns and each column has a CellvaluePresenter and I've 2 buttons ("Save" & "Close") on the same wpf window.
in grid, column 2 has been bound to an business object property and it has DropDown to change value.
I need to disable "Save" button, if any Cell in column 2 has no value(NULL).
in winforms it was easier to go through the cell values. but in WPF it is damn hard to find out where is this value.
can you please tell me an event or any other way to find out if any cell doesn't have a value?
I'm using MVVM pattern for development.
I would appreciate any help on this.
Thanks
Hello,
It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking into your post and I suggest you use the following code in your XamDataGrid’s InitializeRecord event:
isEmpty = true; foreach (var item in xamDataGrid1.Records) { foreach (var subitem in (item as DataRecord).Cells) { if (subitem.Value == null) { isEmpty = false; return; } } }
And define an isEmpty Property of bool type for the Window and bind the Button’s IsEnabled property to it.
Feel free to write me if you have further questions.
the problem is i cannot modify Business Object. I get List<Business object> which is bound to the grid correctly. in cellvalupresenter I've used validation rules to notify user if business object has invalid data.
there is also a mechanism provided to user to set values for business object through text boxes and dropdowns.
all i want to do is, disable the "Save" button if any value is wrong.
now tell me how you would do this with beauty of MVVM.
If you have bound the column to an object property and you set the binding mode = two way,
you can simply check the values of the object properties. Thats the beauty of MVVM, you don't have to iterate through the cell collection of the grid.
i would also recommend to use a Command for your button. this way you can use a CanExecute method to enable/disable the button.