User control implements IBusinessBindable makes object Dirty when Focus is set


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Glad you got it going Smile
Leonard P.
Leonard P.
StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)
Group: Awaiting Activation
Posts: 65, Visits: 306
Thanks Trent! It makes sense, I knew I was missing something, I just didn't know what it was Smile

For anyone who might be interested. Here's the relevant code I had to add to the user control to make it work correctly:

     string _indexText = string.Empty;

        public string IndexText
        {
            get
            {
                return _indexText;
            }
            set
            {           
                _indexText = value;
                OnIndexChanged();               
            }
        }
#region "Event Handlers"
        private EventHandler IndexTextChangedEvent;
        public event EventHandler IndexTextChanged
        {
            add
            {
                IndexTextChangedEvent = (EventHandler)System.Delegate.Combine(IndexTextChangedEvent, value);
            }
            remove
            {
                IndexTextChangedEvent = (EventHandler)System.Delegate.Remove(IndexTextChangedEvent, value);
            }
        }
        protected void OnIndexChanged()
        {
            if (IndexTextChangedEvent != null)
                IndexTextChangedEvent(this, EventArgs.Empty);
        }

        #endregion


Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
This really has nothing to do with SF but rather how .NET interprets a binding.  I have not looked at your sample (and really don't have the time to do this immediately as we are running to catch up now that everyone is back from vacation...but there is already a sample of this in StrataFlix mentioned below).  But when you create a custom property, you will want to create an event and raise that event when the property is changed which will trigger the bindings to update.  For example, if I have a property named Code then I will want to create a CodeChanged event.

There is already a sample of how to do this in the StrataFlix sample.  If you open up the UI assmebly and then look at the WinForms\CLookupControls\PeopleLookupControl it will show you how to implement the IBusinessBindable to a custom property.  This should get you going in the right direction.

Leonard P.
Leonard P.
StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)
Group: Awaiting Activation
Posts: 65, Visits: 306
I studied your sample "IBusinessBindable" project (C#) that comes with StrataFrame. It's pretty much identical to what I am trying to do. It works correctly when BindingProperty is set to "Text", but if you add a custom property "MyTextProperty" that wraps Text (that's what I am doing in my custom control) you'll be able to reproduce this problem.

Please see attached project.  Hopefully it will give you a better idea about what I am dealing with Smile

Thank you for your help.

Attachments
IBusinessBindable.zip (97 views, 721.00 KB)
Leonard P.
Leonard P.
StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)StrataFrame Novice (79 reputation)
Group: Awaiting Activation
Posts: 65, Visits: 306
Hello,

I developed a user control that implements IBusinessBindable interface. The control has one textbox and bunch of buttons. Textbox text is a bindable property, and it's exposed through a custom property IndexText. The control DataSourceUpdateMode is set to DataSourceUpdateMode.OnPropertyChanged (see control code snippet below)

Everything works, but when user clicks on the textbox without changing anything, the BO states becomes Dirty. How can I get arround that?

string _indexText = string.Empty;

public string IndexText

{

get { return _indexText;//syntaxEditorIndexText.Text;

}

set

{

_indexText = value;

syntaxEditorIndexText.Text = _indexText;

//syntaxEditorIndexText.Text = value;

}

}

#region IBusinessBindable Members

private BusinessLayer _BusinessObject;

private string _BindingField = "";

private string _BindingFormat = "";

private string _BindingProperty = "IndexText";

private bool _IgnoreManageUIReadOnlyState = true;

private DataSourceUpdateMode _BindingUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

private ControlUpdateMode _ControlSourceUpdateMode = ControlUpdateMode.OnPropertyChanged;

/// <summary>

/// The field within the business object that is bound to the control

/// </summary>

[Category(BusinessMod.EDITOR_CATEGORY),

Description(BusinessMod.EDITOR_BINDINGUPDATEMODE_DESC)]

public DataSourceUpdateMode DataSourceUpdateMode

{

get

{

return this.BindingUpdateMode;

}

set

{

this.BindingUpdateMode = value;

}

}

////not interface methods

public DataSourceUpdateMode BindingUpdateMode

{

get

{

return _BindingUpdateMode;

}

set

{

_BindingUpdateMode = value;

}

}

/// <summary>

/// Makes the control available or unavailable for editing

/// </summary>

/// <value></value>

/// <remarks></remarks>

[Browsable(false)]

public bool BindingEditable

{

get

{

return this.Enabled;

}

set

{

this.Enabled = value;

}

}

/// <summary>

/// The field within the business object that is bound to the control

/// </summary>

/// <value></value>

/// <remarks></remarks>

[Category(BusinessMod.EDITOR_CATEGORY),

DefaultValue(""),

Description(BusinessMod.EDITOR_BINDINGFIELD_DESC),

Editor(MicroFour.StrataFrame.Extensibility.Constants.TE_BindingFieldEditor, typeof(UITypeEditor))]

public string BindingField

{

get

{

return _BindingField;

}

set

{

_BindingField = value;

}

}

public string BindingFormat

{

get

{

return _BindingFormat;

}

set

{

_BindingFormat = value;

}

}

/// <summary>

/// The property on this control to which the data is bound.

/// </summary>

/// <value></value>

/// <remarks></remarks>

[Category(BusinessMod.EDITOR_CATEGORY),

DefaultValue("PrimaryKey"),

Description(BusinessMod.EDITOR_BINDINGPROPERTY_DESC),

Editor(MicroFour.StrataFrame.Extensibility.Constants.TE_BindingPropertyEditor, typeof(UITypeEditor))]

public string BindingProperty

{

get

{

return _BindingProperty;

}

set

{

_BindingProperty = value;

}

}

/// <summary>

/// The business object that is used to bind the data to this field

/// </summary>

/// <value></value>

/// <remarks></remarks>

[Category(BusinessMod.EDITOR_CATEGORY),

DefaultValue(null),

Description(BusinessMod.EDITOR_BUSINESSOBJECT_DESC)]

public BusinessLayerBase BusinessObject

{

get

{

return this._BusinessObject;

}

set

{

//-- If the business object is being removed, then make sure it is no longer bound

if ((value == null) && (_BusinessObject != null))

{

this._BusinessObject.RemoveFromListOfBoundControls(this);

}

if ((!this.DesignMode) && (value != null))

{

value.AddToListOfBoundControls(this);

}

_BusinessObject = (BusinessLayer)value;

}

}

/// <summary>

/// Gets or sets a value that determines whether the control will allow

/// its editable state to be managed by the bound business object.

/// </summary>

/// <value></value>

/// <returns></returns>

/// <remarks></remarks>

[Category(BusinessMod.EDITOR_CATEGORY),

Description(BusinessMod.EDITOR_CONTROLUPDATEMODE_DESC)]

public System.Windows.Forms.ControlUpdateMode ControlSourceUpdateMode

{

get

{

return this._ControlSourceUpdateMode;

}

set

{

this._ControlSourceUpdateMode = value;

}

}

/// <summary>

/// If True, the control will ignore that auto manage editing state of the business object. The control will not

/// be automatically enabled/disabled by the business object.

/// </summary>

/// <value></value>

/// <remarks></remarks>

[Category(BusinessMod.EDITOR_CATEGORY),

DefaultValue(true),

Description(BusinessMod.EDITOR_IGNOREMANAGE_DESC)]

public bool IgnoreManageUIReadOnlyState

{

get

{

return _IgnoreManageUIReadOnlyState;

}

set

{

_IgnoreManageUIReadOnlyState = value;

}

}

private void ResetControlSourceUpdateMode()

{

this._ControlSourceUpdateMode = ControlUpdateMode.OnPropertyChanged;

}

private bool ShouldSerializeControlSourceUpdateMode()

{

return this._ControlSourceUpdateMode != ControlUpdateMode.OnPropertyChanged;

}

/// <summary>

/// Determines if the binding update mode property is set to default

/// </summary>

/// <returns></returns>

/// <remarks></remarks>

public bool ShouldSerializeBindingUpdateMode()

{

return _BindingUpdateMode != DataSourceUpdateMode.OnPropertyChanged;

}

/// <summary>

/// Resets the binding update mode

/// </summary>

/// <remarks></remarks>

public void ResetBindingUpdateMode()

{

_BindingUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

}

#endregion


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search