1
votes

Hi I have windows form with a Combo filled with 3 options where their values are Guid's and that has a DataBinding to a selected object.

EmployerMemberDefault item = EmployerMemberDefault();
item.GroupUid = Guid.Empty;

cbGroupEmployer.DataBindings.Clear();
cbGroupEmployer.DataBindings.Add("Value", item, "GroupUid");

When I create a new object the property that is databinded to the combo is set to Guid.Empty. If I compile and run, when I create that new object I see "00000000-0000-0000-0000-000000000000" in the combo. Is there any way I can see empty text in the combo instead of the Guid.Empty value?

Thanks.

2
Guid.Empty is a guid whose value is all zeros. When you ToString() this (which is what happens when it shows in the combo), you get what you have. You need to deal with this value specifically if you want it to display as an empty string. - adrianbanks
A ComboBox doesn't have a "Value" property. - LarsTech

2 Answers

1
votes

Change the source property from Guid to Guid?/Nullable<Guid> I haven't done this with Guid, but it works with int/DateTime and other types that do not allow null.

1
votes

"00000000-0000-0000-0000-000000000000" is what Guid.ToString returns. To show something different you'd have to translate that value in some way--i.e. bind to something else that stores the guid and translates it.