This is a migrated thread and some comments may be shown as answers.

Textbox to show different value to the one its bound to?

4 Answers 81 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
madladuk
Top achievements
Rank 2
madladuk asked on 10 Sep 2010, 11:17 AM
This is driving me mad but I'm sure there is an easy way. I have an entity set called "order" that has a status guid that links to a "status" entity. In my page I have a textbox with an image next to it that then opens a radwindow to show the list of available status's this then brings back the statusgiud and statustext. The textbox is bound to the status field TwoWay however If the status has not been used within the result set then the text is not shown until the record is saved and the datasource refreshed. Therefore I need to somehow show the status text? I dont want to be added extra textboxes everywhere a listening to changes on the context. So if there anyway to update the child entity to load it so that the value is shown or some way or binding to one element e.g the statusguid, but showing different text in the field without it updating the datasource.

Thanks
{P

4 Answers, 1 is accepted

Sort by
0
k f
Top achievements
Rank 1
answered on 12 Sep 2010, 03:25 PM
madladuk,

Can post a little more descriptive explanation that's easier to follow?  Are you using MVVM or are you just setting your pages DataContext to the Orders Collection.  Or is the Textbox in some control such as a stack panel and you have the data text set there.

Also, have you verified you're entity set with the way you're implementing is firing INPC?  

Here's what i assume your xaml looks like <textbox x:Name="txt" Text={Binding Order.Status, Mode="TwoWay} />

When the value of Order.Guid changes, try firing the INPC manually. 

The last part, if you're trying to use a control to bind to a ID value but display a status value, can you use a combobox here?

If that doesn't answer your question, maybe try breaking out your question and list it in code so it's easier to follow?

Thanks
0
madladuk
Top achievements
Rank 2
answered on 15 Sep 2010, 02:05 PM
ok I've been banging my head around various forums, still no joy, let me try and give a better example;

Basic entity, of a Customer that links to an entity called Customer Status (Customer.statusguid -> CustomerStatus.statusguid). Thus each customer is assigned a status where the text is held in the CustomerStatus entity;

public class Customer
{
public string name { get; set; }
public EntityCollection<CustomerStatus> CustomerStatus { get; set;}
public Guid statusguid { get; set;}
}

public class CustomerStatus
{
public string statustext { get; set; }
public Guid statusguid { get; set;}
}

So in a textbox on the xaml page [bound to Customer] I set the binding to "CustomerStatus.statustext", TwoWay mode, so this all works and shows the customer status. I then have a button next to this text box that will then show a window where a RIA query returns all of the data from CustomerStatus. The user can then select the new status, when the user closes the window I return a custom event class which has the statusguid, text and the selected item [in this case would be CustomerStatus].

I have tried the following to get the textbox to update the status text;

Setting Customer.statusguid to the one that is returned from the lookup window which does not update the text but when the record is saved and refreshed this is shows. I am guessing you have to do this as this entity value has not been cached, however I dont want to save the record and do a refresh.

If I set Customer.CustomerStatus = my returned selected item, then it says that the entity belongs to a different entity set.

If I setup a new CustomerStatus and copy the values, then assign that to Customer.CustomerStatus then the text on screen updates, however when the record is saved it sees the CustomerStatus entity and a new one and tries to add it to the database for CustomerStatus which fails as it has already been created.

So any ideas of how I can use a lookup style window for entities????

Thanks
P

0
madladuk
Top achievements
Rank 2
answered on 15 Sep 2010, 05:09 PM
ok sorted it, just had to make sure the lookup window was using the same DomainContext, therefore the lookup loads the entities and when setting the value the entity has been cached. 
0
k f
Top achievements
Rank 1
answered on 15 Sep 2010, 05:40 PM
Glad you figured it out.  If you're classes were created like you had listed out.  Below is what I would expect them to look like if you wanted to change one of the properties and have it reflect your bindings.  If you are using Entities generated by RIA to my knowledge they contain an INPC implementation.  If not or you are extending, you'd have to implement your own.  I'm not sure if you are familiar with MVVM Light but it's ViewModelBase has the RaisePropertyChanged contained in this code.  The ReflectionUtility.GetPropertyName saves me from using magic strings.

public class Customer
    {
        private string _name;
        private EntityCollection<CustomerStatus> _customerStatus;
        private Guid _statusguid;
  
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    RaisePropertyChanged(ReflectionUtility.GetPropertyName(() => Name));
                }
            }
        }
  
        public EntityCollection<CustomerStatus> CustomerStatus
        {
            get { return _customerStatus; }
            set
            {
                if (_customerStatus != value)
                {
                    _customerStatus = value;
                    RaisePropertyChanged(ReflectionUtility.GetPropertyName(() => CustomerStatus));
                }
            }
        }
  
        public Guid Statusguid
        {
            get { return _statusguid; }
            set
            {
                if (_statusguid != value)
                {
                    _statusguid = value;
                    RaisePropertyChanged(ReflectionUtility.GetPropertyName(() => Statusguid));
                }
            }
        }
  
    }
  
    public class CustomerStatus
    {
        private string _statustext;
        private Guid _statusguid;
  
        public string Statustext
        {
            get { return _statustext; }
            set
            {
                if (_statustext != value)
                {
                    _statustext = value;
                    RaisePropertyChanged(ReflectionUtility.GetPropertyName(() => Statustext));
                }
            }
        }
  
        public Guid Statusguid
        {
            get { return _statusguid; }
            set
            {
                if (_statusguid != value)
                {
                    _statusguid = value;
                    RaisePropertyChanged(ReflectionUtility.GetPropertyName(() => Statusguid));
                }
            }
        }
  
    }
Tags
General Discussions
Asked by
madladuk
Top achievements
Rank 2
Answers by
k f
Top achievements
Rank 1
madladuk
Top achievements
Rank 2
Share this question
or