I have a DataGridTemplateColumn (created programatically) with a TextBlock for the CellTemplate, and a DatePicker for the CellEditingTemplate.
The DatePicker's value is bound to a DateTime?.
If the cell has a date when the grid is loaded, trying to clear the date results in validation problem -- the empty value is not sent to the bound property.
Is there a setting on the DatePicker to allow empty values (I couldn't find one)?
Is a converter needed to work with the nullable bound property?
Thanks for any insight --
I came across the same problem but it was with a textbox for entering quantity of the product. It had an integer as binded property. It used to act correctly with some quanity entered. But when the textbox got empty after entering some value, then the property had the previous entered value as its current value.
I resolved this by putting a string type property as binded property.
You can do the same. Bind a string type Property with DatePicker. As the date is being picked with DatePicker, you are always sure of the date format. Also you can make DatePickerTextBox as readonly in app styles to not let user input any date by typing.
And in this way when you clear the DatePicker, The underlying binded property will contain null or empty string and I think that is what you are wanting.
You can use that string property in
DateTime.Parse Method to get an equivalent DateTime Object. Try parsing the date in try catch block to handle empty/null string case.
Related
I am trying to figure out how to add placeholder string value on every property inside a property grid that was not changed from the user.
So let's say you are trying to edit some object when you get prompted to do so you will get the following form.
If you changed the color property for example the result would be the following.
I tried to see if there is an attribute but it seems that there is not. DefaultValue is not suitable because the message is a string and the underlying property could be anything.
The question is if this is possible using combinations of Editors and TypeConverters.
Thanks.
We are working with kendo ComboBox using angular js. We bind value to ComboBox using angularjs scope. On preview event, when we assign value on load time (fetched from database) to ComboBox, it takes time to display value on front side in ComboBox. As we marked on preview time, first it binds data to ComboBox and then display value. Is there any solution to display selected value/text on front side, whether the ComboBox get bound or not?
Yes you can do it by applying value in the modal and setting the text accordingly.
Like Your model is countryId and have text value as countryName and name of the combobox is countryComboBox then you can use it like below:
$scope.countryId = 1 (id of which you want to be displayed at first)
$scope.countryComboBox.value(1)
$scope.countryComboBox.text('INDIA')
it will initially set the text to INDIA.
I have a view that contains several ComboBox elements. For some reason old data remains from the previous time the view was opened and I would like to reset the combobox elements in the view every time it is opened. Is there a function that could that for me? I want it to be exactly how it is as if I rendered it the first time with the initial items. Would using setSelectedItem(vItem), setSelectedItemId(vItem), setSelectedKey(sKey), setShowSecondaryValues() help? If so, what do these keywords mean (selectedItem, selectedItemID, selectedKey, secondaryValues)?
Unfortunately you do not provide an example. Normally you bind your UI controls against a model, e.g. JSONModel. In this case the items of your ComboBox controls would be taken from the corresponding model. However, you can use method removeAllItems to achieve the desired behaviour.
UPDATE: Obviously the controls are bound and only the selection should be cleared.
Use setSelectedItem with value null to clear the selection. You could also use the binding to set the selected item automatically by using the selectedKey attribute, see example.
In WPF using IDataErrorInfo and Style I want to create form where I can provide end user three different status while validating data
To make the scenario more clear
1) I have textbox next to it I have icon which provides end user what kind of input textbox expects - Initial status with information icon
2) As soon as user enter data it validates it and decides whether it is valid or not
- most of the time it will show cross (X) icon saying invalid data
3) As it is validating on UpdateSourceTrigger="PropertyChanged" it will turn cross icon to green check mark as soon as it gets validated
i.e
[ ] i (tooltip- Any valid user name )
[Ga ] X (tooltip- Invalid user name. Must be 5 char long)
[Gaurav ] * (it will show only correct icon, meaning valid value)
How can I achieve this using IDataErrorInfo and Style, I tried doing that but as soon as my form gets loaded it invalidates all the data and shows cross icon at the first time. I want to show different tooltip and different icon for three states (Initial info, Invalid data, Valid data)
IDataErrorInfo does not contain any means of representing three states. It only knows "error" and "no error".
The best solution may be to circumvent the use of IDataErrorInfo via the following:
Create a property for each validated field that provides the three-state status for its related field.
Bind ContentControls in the view to these three-state properties.
Set a single style for all of these new ContentControls.
Use Triggers in the Style to assign the ContentControl.ContentTemplate property for the error state and the valid state. For the initial state, use a Setter in the Style itself to display nothing.
You may also have to create properties for each field's tooltip text as well.
you can find a great example here WPF Apps With The Model-View-ViewModel Design Pattern
I have a Form (Compact Framework, actually) with a few fields, a date and a string, among other things. Both TextBox controls are bound to properties in a BindindSource.
The BindindSource has a DataSet as its DataSource property, and the DataMember is a table in a SQL CE database.
When I want to add a new row, I call bindingSource.AddNew(), then bindingSource.MoveLast(). The form shows the default values (as defined in the DataSet) and I can edit all the fields.
To save the form, I call bindingSource.EndEdit() and insert the values from the DataSet row into the database, using a TableAdapter method. The date makes it into the database, the string does not. Instead, the default value for the string is saved, not the value that I typed in the text box.
When I inspect the data in the DataSet table's row after calling EndEdit(), the date field is updated with the data from the form, the string is not.
Oddly enough, when I edit an existing row with the same form (without calling AddNew), the string field is updated and persisted just fine. So this only happens after calling AddNew() on the BindingSource. What am I missing? Where should I start looking?
The code is a bit too much to post here, unfortunately.
I found the issue - I had accidentially select the same column in the BindingSource for both the Tag and the Text property of the TextBox. I think what happened was that the Text was written back first, the Tag second, and because the Tag was not updated, it overwrote the modified value.