DropDownDataGrid About the state where the value is already selected in the initial state

Currently, I am using DropDownDataGrid to create a simple form that allows me to select items in the database.

However, it does not behave as expected when the page is loaded and this form is displayed for the first time.

The symptom is that in Drop DownDataGrid, the user hasn't selected anything yet, but it looks like the item is already selected.
(The item is not selected and is empty, but the x button can be pressed)

The reason I think is that this Drop DownDataGrid uses a RequiredValidator, so it binds an object with the same structure as a table with a database, but since this table has a not null constraint, the initial value of an int type column I think it's because it contains 0.

What approach do I need to take to ensure that nothing is completely selected when displaying this form?
Or is it possible to activate the X button of Drop Down DataGrid arbitrarily?

I have been suffering from this problem for a very long time.
I need help.
I look forward to working with you.


Added screenshots.
ProductNo is of type int and is not null.
ProductName is of type string.

I tried changing the target of RequiredValidator from ProductName to ProductNo, but DefaultValue did not work well.
I don't understand this clearly and I don't know how to use it.


The red frame part of the form is the state where the page is loaded.
Nothing is displayed, but you can press the x button with something already selected.


It seems that you need to set the DefaultValue of the RequiredValidator. Indeed a number's default value s 0 and if you have an item with value 0 it will be selected.

thank you for your answer.

I specified DefaultValue but it didn't work. Added a screenshot of the code. Please check.

Also, is it possible to write the same code as pressing the x button at any time?
I think it would work if I added the process of pressing the x button when loading the page and cleared the form.

I've tried it many times, but I'm still worried because I can't solve it.

I know that some of the binding Recipe objects have a not null constraint and not all elements are null.

Since the int type column (ProductNo) with not null constraint is set to 0 as the initial value instead of null, it looks like an empty element is selected when the page is loaded, as shown in the screenshot. Imagine that it is.

However, setting DefaultValue to 0 does not work.

In the initial state, 0 is stored in ProductNo and null is stored in ProductName.

My question is missing and I find it difficult for you to answer.
What information do I need to add?
I want to solve this anyway.

Your DropDownDataGrid has a value so this is why it displays the clear button. You can just set the AllowClear property to false. You can't clear it anyway as your data-binding it to a non-nullable property.

I'm sorry I accidentally deleted the reply, so I'll resend it.

Thank you for your reply.
Setting AllowClear to False is a great idea to solve the situation where something seems to the user to be selected.

But I have another challenge.
That is to use the Required Validator effectively.

It appears empty in the DropDownDataGrid, but it actually has a value.

Initially, ProductNo (not null constraint) contains 0 and ProductName contains null.

Therefore, verification does not work effectively when submitting without the user selecting anything.

korchev told me the existence of DefaultValue to solve this, but I haven't mastered it.

I tried specifying DefaultValue = 0; for both ProductNo and ProductName, but even if I submit it, the verification is cleared.

What could be the cause of this?
Can you give me an idea of ​​how to use validation effectively?
I'm really sorry for the rudimentary question.

The DefaultValue of the RequiredValidator specifies what value is considered as default. If the component's Value equals the DefaultValue the validator is invalid. Here is the source.