Click here to Skip to main content
15,895,256 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: A General Question About DataGrid Controls Pin
Henry Minute21-Jan-11 5:49
Henry Minute21-Jan-11 5:49 
GeneralRe: A General Question About DataGrid Controls Pin
Roger Wright21-Jan-11 7:04
professionalRoger Wright21-Jan-11 7:04 
GeneralRe: A General Question About DataGrid Controls Pin
Henry Minute21-Jan-11 8:00
Henry Minute21-Jan-11 8:00 
GeneralRe: A General Question About DataGrid Controls Pin
Roger Wright21-Jan-11 17:17
professionalRoger Wright21-Jan-11 17:17 
GeneralRe: A General Question About DataGrid Controls Pin
Gregory Gadow24-Jan-11 17:57
Gregory Gadow24-Jan-11 17:57 
AnswerRe: A General Question About DataGrid Controls [modified] Pin
GenJerDan21-Jan-11 11:29
GenJerDan21-Jan-11 11:29 
GeneralRe: A General Question About DataGrid Controls Pin
Roger Wright21-Jan-11 17:12
professionalRoger Wright21-Jan-11 17:12 
QuestionReusable Lookup Control [modified] Pin
Ed Hill _5_20-Jan-11 0:06
Ed Hill _5_20-Jan-11 0:06 
I'm trying to create a lookup that can be used in many places within my application, it is to display a list of activities. It is to be used in several places, each with their own DataContext, as the application dosn't have one static context used by all forms. All instances of the context are from the same Entity Model.
The first issue i had was on one form i have a databound list view containing usercontrols as the item template, this user control contained the lookup in question. The lookup needs to share the same context as the form. This was a bit of an issue as i could not find an simple way of doing this, so i created an event in the lookup that requests a context, this is handled by the form.
The lookup contains a Dependancy Property called Value, of the type Activity, the user control binds its Activity to the Value, but also shows some other information about the activity, this is where my issue is, this fails to update when the activity is changed. Ideally i would like to avoid any process that manually updates this information, and have it done through bindings, any help would be greatly appreciated.

Form - For Simplicity i've moved the required parts of the usercontrol into the form
<ListView Name="lvwTimeCharges" Margin="0,34,0,0">
     <ListView.ItemTemplate>
         <DataTemplate>
             <StackPanel Orientation="Horizontal">
                 <my:uscActivitiesLookup Width="200" Value="{Binding Path='Activity', Mode=TwoWay}" ContextRequested="child_ContextRequested"/>
                 <Label Content="{Binding Path='Activity.sActivityCode'}"/>
             </StackPanel>
         </DataTemplate>
     </ListView.ItemTemplate>
 </ListView>
cEntities Context = new cEntities();
Staff s = null;

Guid gStaff = new Guid("99772C66-B379-4124-839B-3427AE3481C4");
Guid gRate = new Guid("987E3837-F099-481E-BC5C-544BC04361BC");

public MainWindow()
{
    InitializeComponent();

    s = (from staff in Context.Staff where staff.gStaffID == s select staff).First();
    DataContext = s;

    lvwTimeCharges.ItemsSource = (from c in s.Charges where c.Rate.gRateID == gRate select c);

}

private void child_ContextRequested(iWantzContext sender, EventArgs e)
{
    sender.Context = Context;
}

private void button1_Click(object sender, RoutedEventArgs e)
{
    Context.SaveChanges();
}


Lookup
<ComboBox Name="cmbActivities" SelectionChanged="ComboBox_SelectionChanged" DisplayMemberPath="sActivityDescription"/>

public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(Activity),typeof(uscActivitiesLookup),new PropertyMetadata(ValueChangedCallback));
        
        private static void ValueChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            if ((obj as uscActivitiesLookup).Context != null)
                (obj as uscActivitiesLookup).cmbActivities.SelectedItem = e.NewValue;
        }

        public uscActivitiesLookup()
        {
            InitializeComponent();
        }

        public Activity Value
        {
            get { return (Activity)GetValue(ValueProperty); }
            set {SetValue(ValueProperty,  value);}
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (Context != null)
                Value = cmbActivities.SelectedItem as Activity;
        }
        private IEnumerable<TimeRecordingActivity> lookupValues;
        private void PopulateCombo()
        {
            lookupValues = from a in _context.Activities where a.bDeleted == false select a ;
            cmbActivities.ItemsSource = lookupValues;

            if (Value != null)
                cmbActivities.SelectedItem = Value;
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            ContextRequested(this, null);
        }

        #region iWantzContext Members

        public event ContextSharing.ContextRequestedEventHandler ContextRequested;
        
        cEntities _context = null;
        public cEntities Context
        {
            get 
            {
                return _context;
            }
            set
            {
                _context = value;
                PopulateCombo();
            }
        }

        #endregion


The sActivity Code fails to update, but if a savechanges is performed on the context and the form is refreshed the Activity has been successfully updated.

modified on Friday, January 21, 2011 6:47 AM

AnswerRe: Reusable Lookup Control Pin
Ian Shlasko20-Jan-11 6:09
Ian Shlasko20-Jan-11 6:09 
GeneralRe: Reusable Lookup Control Pin
Ed Hill _5_20-Jan-11 22:15
Ed Hill _5_20-Jan-11 22:15 
GeneralRe: Reusable Lookup Control Pin
Ian Shlasko21-Jan-11 3:44
Ian Shlasko21-Jan-11 3:44 
GeneralRe: Reusable Lookup Control Pin
Ed Hill _5_21-Jan-11 1:50
Ed Hill _5_21-Jan-11 1:50 
AnswerRe: Reusable Lookup Control Pin
Ed Hill _5_21-Jan-11 5:58
Ed Hill _5_21-Jan-11 5:58 
QuestionPlease help on LINQ Order By in VB.NET Pin
kishan NM19-Jan-11 2:30
kishan NM19-Jan-11 2:30 
AnswerRe: Please help on LINQ Order By in VB.NET Pin
Ian Shlasko19-Jan-11 2:48
Ian Shlasko19-Jan-11 2:48 
GeneralRe: Please help on LINQ Order By in VB.NET Pin
kishan NM19-Jan-11 3:52
kishan NM19-Jan-11 3:52 
GeneralRe: Please help on LINQ Order By in VB.NET Pin
Ian Shlasko19-Jan-11 4:40
Ian Shlasko19-Jan-11 4:40 
GeneralRe: Please help on LINQ Order By in VB.NET Pin
kishan NM19-Jan-11 6:53
kishan NM19-Jan-11 6:53 
GeneralRe: Please help on LINQ Order By in VB.NET Pin
Ian Shlasko19-Jan-11 7:56
Ian Shlasko19-Jan-11 7:56 
AnswerRe: Please help on LINQ Order By in VB.NET Pin
dasblinkenlight19-Jan-11 4:49
dasblinkenlight19-Jan-11 4:49 
AnswerRe: Please help on LINQ Order By in VB.NET Pin
#realJSOP19-Jan-11 7:27
mve#realJSOP19-Jan-11 7:27 
QuestionUser account rights Pin
marca29217-Jan-11 0:50
marca29217-Jan-11 0:50 
AnswerRe: User account rights Pin
_Erik_17-Jan-11 3:07
_Erik_17-Jan-11 3:07 
GeneralRe: User account rights [modified] Pin
marca29217-Jan-11 21:32
marca29217-Jan-11 21:32 
AnswerRe: User account rights Pin
Ravi Sant18-Jan-11 1:12
Ravi Sant18-Jan-11 1:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.