none
Combo Box Inside DataForm ?

    Question

  • Hi Everyone,

    I have a Child Window with a DataForm in it for adding a new record, I want to use a combobox to populate the ID fields and the user should just see the names from my lookup table, then the ID will save back to the database, the problem is that I cant get the combobox to populate inside of the dataform. It is coming back blank but I have a combo box outside a dataform on my mainpage using the same datasource to I know it works.

     I am using a DomainDataSource as the ItemSource for the Combo Box. This domain data source is in my Child Window XAML, I would also like to know if its possible to set this to a DomainDataSource that I have already loaded in my main page that the child window is loading from?

     

    Sort of two questions, any help with this would be great.

     

    Thanks in advance! Big Smile

     

    Here is my XAML for my ChildWindow.Xaml DataForm:

     

    <dataForm:DataForm x:Name="NewScheduledTeamDataForm" AutoGenerateFields="False" AutoCommit="True" AutoEdit="True" CommandButtonsVisibility="None">
    <dataForm:DataForm.EditTemplate>
    <DataTemplate>
    <StackPanel>

    <dataForm:DataField Label="Team">
    <TextBox Text="{Binding Team, Mode=TwoWay}" />
    </dataForm:DataField>
    <dataForm:DataField Label="Unit ID">
    <ComboBox x:Name="cboSelectedUnit" ItemsSource="{Binding Data, ElementName=UnitListDataSource}" Height="22">
    <ComboBox.ItemTemplate>
    <DataTemplate>
    <StackPanel>
    <StackPanel Orientation="Horizontal">
    <TextBlock Text="Unit "/>
    <TextBlock Text="{Binding Unit}"/>
    </StackPanel>
    </StackPanel>
    </DataTemplate>
    </ComboBox.ItemTemplate>
    </ComboBox>
    </dataForm:DataField>
    <dataForm:DataField Label="Case Number">
    <TextBox Text="{Binding CaseNumber, Mode=TwoWay}" />
    </dataForm:DataField>
    <dataForm:DataField Label="TeamTypeID">
    <TextBox Text="{Binding TeamTypeID, Mode=TwoWay}" />
    </dataForm:DataField>
    <dataForm:DataField Label="TeamStatusID">
    <TextBox Text="{Binding TeamStatusID, Mode=TwoWay}" />
    </dataForm:DataField>
    <dataForm:DataField Label="TeamDate">
    <TextBox Text="{Binding TeamDate, Mode=TwoWay}" />
    </dataForm:DataField>
    <dataForm:DataField Label="TeamTimeSlotID">
    <TextBox Text="{Binding TeamTimeSlotID, Mode=TwoWay}" />
    </dataForm:DataField>
    <dataForm:DataField Label="TeamNotes">
    <TextBox Text="{Binding TeamNotes, Mode=TwoWay}" />
    </dataForm:DataField>
    </StackPanel>
    </DataTemplate>
    </dataForm:DataForm.EditTemplate>
    </dataForm:DataForm>
      

     Here is my XAML for my ChildWindow.Xaml DataSource ( This is also on my MainPage but I dont know how to call to it from my ChildWindow:

     

            <riaControls:DomainDataSource x:Name="UnitListDataSource" LoadSize="20" QueryName="GetLU_Unit" AutoLoad="True">
    <riaControls:DomainDataSource.DomainContext>
    <ds:WRPTeamSchedulerDomainContext/>
    </riaControls:DomainDataSource.DomainContext>
    <riaControls:DomainDataSource.SortDescriptors>
    <riaData:SortDescriptor PropertyPath="Unit" Direction="Ascending" />
    </riaControls:DomainDataSource.SortDescriptors>
    </riaControls:DomainDataSource>
      Here is my XAML for my MainPage.Xaml DataSource ( This page has a button that brings up the Childwindow, its the same datasource as above but I feel its redundent to type it twice, once in the childwindow.xaml and once in the mainpage.xaml but im not sure how to call to a datasource in my mainpage.xaml from my childpage.xaml?):

     

            <riaControls:DomainDataSource x:Name="UnitListDataSource" LoadSize="20" QueryName="GetLU_Unit" AutoLoad="True">
    <riaControls:DomainDataSource.DomainContext>
    <ds:WRPTeamSchedulerDomainContext/>
    </riaControls:DomainDataSource.DomainContext>
    <riaControls:DomainDataSource.SortDescriptors>
    <riaData:SortDescriptor PropertyPath="Unit" Direction="Ascending" />
    </riaControls:DomainDataSource.SortDescriptors>
    </riaControls:DomainDataSource>
    Wednesday, July 22, 2009 5:23 PM

Answers

  • My bad, i did not get the completely clear picture from the start. Mostly good, but small details can be devastating Smile

    I was taking the DomainContext in the datasource when indeed you want the full DomainDataSource.

    Actually, the answer is probably simpler than it looked:

    public ScheduleNewTeamWindow(DomainDataSource dds)
            {
                InitializeComponent();
                NewScheduledTeam = new tbl_TeamSchedule();
                NewScheduledTeamDataForm.CurrentItem = NewScheduledTeam;
                NewScheduledTeamDataForm.BeginEdit();
                ComboBox myUnit = (ComboBox)NewScheduledTeamDataForm.FindNameInContent("cboUnit");
                Binding b = new Binding("Data");
                b.Source = dds;
               myUnit.SetBinding(
    ItemsControl.ItemsSourceProperty, b);
            }

            private void btnScheduleTeam_Click(object sender, RoutedEventArgs e)
            {
                ScheduleNewTeamWindow ScheduleTeamWindow = new ScheduleNewTeamWindow(this.UnitListDataSource);
     

    If the systems accepts to re-use the DomainDataSource, you'll be fine, otherwise, you will need an App static method to create a DomainDataSource with your required specs (i.e: as the Xml declares it) and use it for the binding. Other possible problem, you might need to add the DDS somewhere in the control tree.

    Thursday, July 23, 2009 2:17 PM
  • I just got a combobox to work in my dataform as it should and did it with no added procedural code. I realize your situation is a little different since you are using a child form but take a look at what I did and see if that helps.  I am very interested in what happens with your app because I will be doing the same sort of thing soon.

    http://silverlight.net/forums/t/114676.aspx

    Tuesday, July 28, 2009 5:31 PM

All replies

  • >>would also like to know if its possible to set this to a DomainDataSource that I have already loaded in my main page that the child window is loading from?

     That is exactly what I would like to know.  Please post here if you figure it out.

     

    Wednesday, July 22, 2009 6:21 PM
  • Unless i confuse things, what you guys are referring to as pages, look like user controls inside the same page.

    Ok, here is how i would try to resolve this issue:

    Have a static DomainDataSource at your App level

    In the Click event (or event that show the ChildPage), make sure you take the Combo's DomainContext and assign it to your static.
    Then, in the ChildPage constructor, assign the static DDS to the DomainContext of your new Combo after InitializeComponents().

    You might have to set the main page Combo DomainContext to null before assigning it to a new Combo.

    Hope this helps.

    Thursday, July 23, 2009 11:28 AM
  • Thanks for the reply,

    When I was talking about pages, I actually mean a view that I added as a "SilverlightChildWindow". Are we talking about the same thing? My question now is how do I reference to controls on my ChildPage from my MainPage in code that shows the ChildWindow? Thanks!

    Thursday, July 23, 2009 11:57 AM
  • Creating your child page means handling a button click event (or any other event that might bring the child page).

    You probably have code creating and showing the child page like:

    MyChildPage page = new MyChildPage();
    page.Show();

    now, all you need is that between these 2 lines, you do something like:

    page.UnitListDataSource.DomainContext = this.UnitListDataSource.DomainContext

    But its possible that you are restricted and instead need to do:

    DomainContext dc = this.UnitListDataSource.DomainContext
    this.UnitListDataSource.DomainContext = null;
    page.UnitListDataSource.DomainContext = dc;

    Hope this helps.

    Thursday, July 23, 2009 12:15 PM
  • Hi, I'm running into an exception that the DomainContext can only be set once.ScheduleTeamWindow.UnitListDataSource is not being recognized because I don't have an object named UnitListDataSource in my ChildWindow correct? Using this code, don't I still need a datasource in both pages names UnitListDataSource otherwise how will ScheduleTeamWindow.UnitListDataSource work?

    Thursday, July 23, 2009 1:40 PM
  • My bad, i did not get the completely clear picture from the start. Mostly good, but small details can be devastating Smile

    I was taking the DomainContext in the datasource when indeed you want the full DomainDataSource.

    Actually, the answer is probably simpler than it looked:

    public ScheduleNewTeamWindow(DomainDataSource dds)
            {
                InitializeComponent();
                NewScheduledTeam = new tbl_TeamSchedule();
                NewScheduledTeamDataForm.CurrentItem = NewScheduledTeam;
                NewScheduledTeamDataForm.BeginEdit();
                ComboBox myUnit = (ComboBox)NewScheduledTeamDataForm.FindNameInContent("cboUnit");
                Binding b = new Binding("Data");
                b.Source = dds;
               myUnit.SetBinding(
    ItemsControl.ItemsSourceProperty, b);
            }

            private void btnScheduleTeam_Click(object sender, RoutedEventArgs e)
            {
                ScheduleNewTeamWindow ScheduleTeamWindow = new ScheduleNewTeamWindow(this.UnitListDataSource);
     

    If the systems accepts to re-use the DomainDataSource, you'll be fine, otherwise, you will need an App static method to create a DomainDataSource with your required specs (i.e: as the Xml declares it) and use it for the binding. Other possible problem, you might need to add the DDS somewhere in the control tree.

    Thursday, July 23, 2009 2:17 PM
  • As a last resort, here is something to test for you. Put it in your child window Contructor or Loaded event.

    DomainDataSource dds = new DomainDataSource();
    dds.Name = "UnitListDataSource";
    dds.DomainContext =
    new WRPTeamSchedulerDomainContext();
    dds.SortDescriptors.Add(
    new SortDescriptor("Unit", SortDirection.Ascending));
    this.LayoutRoot.Children.Add(dds);
    Binding b = new Binding("Data");
    b.Source = dds;
    ComboBox myUnit = (ComboBox)NewScheduledTeamDataForm.FindNameInContent("cboUnit");
    myUnit.SetBinding(
    ComboBox.ItemsSourceProperty, b);

    Keep me posted :-)

    Thursday, July 23, 2009 2:56 PM
  • Thanks for your help MComeauS2S,

    I also found this post from you that will help when passing information from page to page for anyone who is interested.

    http://silverlight.net/learn/tutorials/MultiPageApps_cs.aspx

    Thursday, July 23, 2009 5:00 PM
  • cAN yOU  pLEASE Explain the code that you finally got working as i am facing a similar problem...

    thnxx

    Sunday, July 26, 2009 7:51 AM
  • Bacarat

    >> I want to use a combobox to populate the ID fields and the user should just see the names from my lookup table, then the ID will save back to the database, the problem is that I cant get the combobox to populate inside of the dataform.

     

    Were you able to get this to work?  If so, could you elaborate on it a bit.  I need to do the same thing.

     

    Monday, July 27, 2009 5:46 PM
  •  I'm still unable to get the combobox to populate, but I was able to pass the data source usning the above examples. What problems are you having?

    Monday, July 27, 2009 6:59 PM
  • How about going back to basics and making a sample project showing the issue ? Then zip and upload it somewhere so we can try our hands at solving it ?

    Can you reproduce the issue with stubbed data?

    Tuesday, July 28, 2009 7:22 AM
  •  MComeauS2S,

    Attached is an example project I made of what i am trying to do. You will see on Home.xaml that I have a datagrid of employees, when you hit the "Add Employee" button the child window will appear. The combobox for "State" will not populate inside the dataform and it should populate a list and then save the ID to the datasource, along with grabbing the list of stated from a datasource that I declared on my main page. For now the datasource is on both pages so you could see what I was talking about. Thanks for your help!

    http://rapidshare.com/files/261107314/DropdownInChildWindow.zip.html

    Tuesday, July 28, 2009 3:23 PM
  • Ok, i can get things to show, but it requires a bit of hand code (until the behavior is solved).

    Not sure why it fails, but here,s a workaround (Based on your sample):

     

            public AddNewEmployeeWindow()
            {
                InitializeComponent();
                NewEmployee = new tbl_Employees();
                NewEmployeeDataForm.CurrentItem = NewEmployee;
                NewEmployeeDataForm.BeginEdit();
    	    this.StateListDataSource.LoadedData += new EventHandler(StateListDataSource_LoadedData);
            }
    
    	void StateListDataSource_LoadedData(object sender, LoadedDataEventArgs e)
    	{
    	    ComboBox o = NewEmployeeDataForm.FindNameInContent("cboState") as ComboBox;
    	    o.ItemsSource = this.StateListDataSource.Data;
    	}
    

     

    Hope it helps

    Tuesday, July 28, 2009 5:06 PM
  •  Thanks,

     Im running into an exception after building on this code:

     

            public ScheduleNewTeamWindow()
            {
                InitializeComponent();
                NewScheduledTeam = new tbl_TeamSchedule();
                NewScheduledTeamDataForm.CurrentItem = NewScheduledTeam;
                NewScheduledTeamDataForm.BeginEdit();
                this.UnitListDataSource.LoadedData += new EventHandler(UnitListDataSource_LoadedData);
    
            }
    
            void UnitListDataSource_LoadedData(object sender, LoadedDataEventArgs e)
            {
                ComboBox o = NewScheduledTeamDataForm.FindNameInContent("cboUnit") as ComboBox;
                o.ItemsSource = this.UnitListDataSource.Data;
            }
      
    this.UnitListDataSource.LoadedData += new EventHandler(UnitListDataSource_LoadedData);

    any ideas?

    Error    1    No overload for 'UnitListDataSource_LoadedData' matches delegate 'System.EventHandler'

     

    Tuesday, July 28, 2009 5:29 PM
  • I just got a combobox to work in my dataform as it should and did it with no added procedural code. I realize your situation is a little different since you are using a child form but take a look at what I did and see if that helps.  I am very interested in what happens with your app because I will be doing the same sort of thing soon.

    http://silverlight.net/forums/t/114676.aspx

    Tuesday, July 28, 2009 5:31 PM
  • Thank You,

    I'm now able to populate the combobox, do I need to call submit changes to both my combo box datasource as well as my forms datasource? Thanks!

    Tuesday, July 28, 2009 6:27 PM
  • Not sure why you would need to call Submit changes for the combo box?  I don't think you would.  The combo box is using the GetUnitsListDataSource to populate its list of items.  But that is a one way trip.  The combo box's underlying value is the LU_Unit member of the SheduledTeam (the item the Dataform is bound to.).  If I have that right, you would only need to update the Dataforms Datasource. 

    The only thing I noticed is that code in ScheduleTeamWindow_Closed.  Haven't got to the child windows yet, but I would think the Closed event happens after the window is closed, and therefore it isn't available, so you never get inside the IF statement to do the update.  I could be all wrong there, but just thought I'd mention it.

    Tuesday, July 28, 2009 6:44 PM
  • Your right, no need to call the update to both datasources, just the forms datasource. The changes are being saved to the database and the closed event is firing fine it looks like, however im running into a strange problem. Instead of applying the selected key from my combobox to the new record in tbl TeamSchedule, the domaincontext is saving a new record in LU Unit and then applying that new key to the new record in tbl teamschedule after I call submitchanges. Any ideas as to why it would make a new record in my lookup and then apply that records key to my new record in tbl teamschedule? Maybe its my binding in XAML?
    <dataForm:DataField Label="Unit ID">
        <Grid>
          <riaControls:DomainDataSource x:Name="GetUnitListDataSource" QueryName="GetLU_Unit"  AutoLoad="True" DomainContext="{Binding Source={StaticResource WRPTeamSchedulerDomainContext}}"></riaControls:DomainDataSource>
          <ComboBox x:Name="cboUnit" ItemsSource="{Binding Data, ElementName=GetUnitListDataSource}" SelectedItem="{Binding LU_Unit, Mode=TwoWay}" DisplayMemberPath="Unit" />
        </Grid>
    </dataForm:DataField>
    Tuesday, July 28, 2009 6:50 PM
  • I was having that happen too.  Look at the XAML I posted under Grid.Resources.  There I am placing a domaincontext tag.  That represents one instance of my domain context.  Then look at the DDS XAML where it uses that resource.  That way, both the form's DDS and the combo box's DDS are using the same instance.  Then that problem went away for me.

    Tuesday, July 28, 2009 7:09 PM
  • Fantastic! All is working well now. My form was being bound to a new record from code in my ChildWindow, but the changes where actually being submitted to a DomainDataSource from my Master XAML per the walkthrough so I changed it to save the changes to a new DomainDataSource i called from my ChildWindow. Correct me if i am wrong here, but this is almost the same way that you had done, only my form or any control for that matter is not actually being bound to the datasource that i am submitting my changes to. For example:

    The following code shows the Child Window and when it is closed, it adds a new record to the Domain Context:

            private void btnScheduleTeam_Click(object sender, RoutedEventArgs e)
            {
                ScheduleNewTeamWindow ScheduleTeamWindow = new ScheduleNewTeamWindow();
                ScheduleTeamWindow.Closed += new EventHandler(ScheduleTeamWindow_Closed);
                ScheduleTeamWindow.Show();
            }
    
            void ScheduleTeamWindow_Closed(object sender, EventArgs e)
            {
                ScheduleNewTeamWindow team = (ScheduleNewTeamWindow)sender;
                if (team.NewScheduledTeam != null)
                {
                    WRPTeamSchedulerDomainContext _WRPTeamSchedulerDomainContext = (WRPTeamSchedulerDomainContext)(TeamScheduleDataSource.DomainContext);
                    _WRPTeamSchedulerDomainContext.tbl_TeamSchedules.Add(team.NewScheduledTeam);
                }
    
            }

     

    The following code from my Child Window binds my Dataform to a new record and then I call the submit changes on a new DataSource from my Child Window:

        public partial class ScheduleNewTeamWindow : ChildWindow
        {
            public tbl_TeamSchedule NewScheduledTeam { get; set; }
    
            public ScheduleNewTeamWindow()
            {
                InitializeComponent();
                NewScheduledTeam = new tbl_TeamSchedule();
                NewScheduledTeamDataForm.CurrentItem = NewScheduledTeam;
                NewScheduledTeamDataForm.BeginEdit();
            }
    
            private void OKButton_Click(object sender, RoutedEventArgs e)
            {
                NewScheduledTeamDataForm.CommitEdit();
                FormSource.SubmitChanges();
                this.DialogResult = true;
            }
    
            private void CancelButton_Click(object sender, RoutedEventArgs e)
            {
                NewScheduledTeam = null;
                NewScheduledTeamDataForm.CancelEdit();
                this.DialogResult = false;
            }
        }
        }

      

    The following XAML shows how I bound my Combobox, as well as called a new DataSource that I actualy Submit Changes to on button press in the above C sharp code:

    <Grid.Resources>
    <ds:WRPTeamSchedulerDomainContext x:Key="WRPTeamSchedulerDomainContext" />
    </Grid.Resources>
    
    <riaControls:DomainDataSource x:Name="FormSource" QueryName="GetTbl_TeamSchedule"  AutoLoad="True" DomainContext="{Binding Source={StaticResource WRPTeamSchedulerDomainContext}}">
    </riaControls:DomainDataSource>
    
     <dataForm:DataForm x:Name="NewScheduledTeamDataForm" AutoGenerateFields="False" AutoCommit="True" AutoEdit="True" CommandButtonsVisibility="None">
                <dataForm:DataForm.EditTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <dataForm:DataField Label="Team">
                                <TextBox Text="{Binding Team, Mode=TwoWay}" />
                            </dataForm:DataField>
                            <dataForm:DataField Label="Unit ID">
                                <Grid>
                                    <riaControls:DomainDataSource x:Name="GetUnitListDataSource" QueryName="GetLU_Unit"  AutoLoad="True" DomainContext="{Binding Source={StaticResource WRPTeamSchedulerDomainContext}}"></riaControls:DomainDataSource>
                                    <!--<ComboBox x:Name="cboUnit" ItemsSource="{Binding Data, ElementName=GetUnitListDataSource}" SelectedItem="{Binding LU_Unit, Mode=TwoWay}" DisplayMemberPath="Unit" />-->
                                    <ComboBox x:Name="cboUnit" ItemsSource="{Binding Data, ElementName=GetUnitListDataSource}" SelectedItem="{Binding LU_Unit, Mode=TwoWay}">
                                        <ComboBox.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="Unit "/>
                                                        <TextBlock Text="{Binding Unit}"/>
                                                    </StackPanel>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ComboBox.ItemTemplate>
                                    </ComboBox>
                                </Grid>
                            </dataForm:DataField>
                            <dataForm:DataField Label="Case Number">
                                <TextBox Text="{Binding CaseNumber, Mode=TwoWay}" />
                            </dataForm:DataField>
                            <dataForm:DataField Label="TeamTypeID">
                                <TextBox Text="{Binding TeamTypeID, Mode=TwoWay}" />
                            </dataForm:DataField>
                            <dataForm:DataField Label="TeamStatusID">
                                <TextBox Text="{Binding TeamStatusID, Mode=TwoWay}" />
                            </dataForm:DataField>
                            <dataForm:DataField Label="TeamDate">
                                <TextBox Text="{Binding TeamDate, Mode=TwoWay}" />
                            </dataForm:DataField>
                            <dataForm:DataField Label="TeamTimeSlotID">
                                <TextBox Text="{Binding TeamTimeSlotID, Mode=TwoWay}" />
                            </dataForm:DataField>
                            <dataForm:DataField Label="TeamNotes">
                                <TextBox Text="{Binding TeamNotes, Mode=TwoWay}" />
                            </dataForm:DataField>
                        </StackPanel>
                    </DataTemplate>
                </dataForm:DataForm.EditTemplate>
            </dataForm:DataForm>
    
            <Button x:Name="CancelButton" Content="Cancel" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" Click="CancelButton_Click" />
            <Button x:Name="OKButton" Content="OK" Width="75" Height="23" HorizontalAlignment="Right"  Margin="0,12,79,0" Grid.Row="1" Click="OKButton_Click" />
        </Grid>
     

    Can anyone confirm i am doing this correctly? Everything seems to be saving fine now. Thanks!
    Tuesday, July 28, 2009 8:05 PM
  • Hi guys,

    I'm used to work things a bit different and i might be wrong with my thinking but here's what i usually do.

    I consider a list of Items and add/edit an item should be bound to the same DataContext, even if i handle these in 2 separate windows or forms.

    For this, what i do is that when i click my Add button, i create the item instance in my list form, then pass that instance to the edit form via the constructor or a property after construction.

    Suppose i want the ability to have nested forms to work on related data, like, Client List -> New Client -> New Client Address, i'll share the datacontext from one form to the next. I mean that i will make sure i'm using the same datacontext for all these item. That way, when i save the New Client, i'll be saving his new address at the same time, and my Client List gets updated without having to query the database again. If it fails, or if i cancel, the new address does not stick in the database.

    if i need to pass a datacontext, i'll also do it from the constructor. Then i'll set the datacontext on the domaindatasource right after InitializeComponents(). Yes, that requires coding, but there is no way to reference my parent form for its datacontext and it keeps things bound together.

    Client List
        DomainDataSource <- DataContext
        ListView (or ListBox) use DDS.
            Edit Row -> Child Edit Window with Current Item and DataContext
        Add Button -> Child EditWindow with New Item
        Form Closed Handler -> If DialogResult is true, SaveChanges()

    Child Edit Window(Item, DataContext)  -> Set DomainContext on DDS for Combobox
        DataForm uses Item
            DDS for Combobox
            DataFields
                ....
               ComboBox using DDS + Add Button for new Item -> Child Edit Window with New Item (and DataContext if that subform has to add/modify other data or display other related data)
        Save Button -> Set DialogResult to true (this closes the child window)
        Cancel Button -> Set DialogResult to false (this also closes the child window)

    I know this isnt conventional descriptions, but it should give a rough idea of what i'm trying to represent.

    Also note that i'm not adding my objects to the DataContext until i get to the Form Closed Handler, form validation should prevent returning with invalid data when i hit the Save Button.

    Wednesday, July 29, 2009 8:12 AM
  • this.UnitListDataSource.LoadedData += new EventHandler(UnitListDataSource_LoadedData);

    any ideas?

    Error    1    No overload for 'UnitListDataSource_LoadedData' matches delegate 'System.EventHandler'

     Yes i do know what happened. This text editor is not friendly with XML (or HTML) type text if you use its insert Code feature. Here's what should have shown: 

    this.StateListDataSource.LoadedData += new EventHandler<LoadedDataEventArgs>(StateListDataSource_LoadedData);

     
    Wednesday, July 29, 2009 8:30 AM
  •  Cool, that seems to work. Thanks!

    Wednesday, July 29, 2009 11:49 AM
  • Please can anyone help me with my project i followed your example of combobox and it works but.. my problem now is that when the comboboxes load they change the displayed data in the datagrid... and also my new employee child window is not saving the data pls help./// Crying

    link to my project files

    http://rapidshare.com/files/261967586/TIMSCDRREv.rar.html

    Thursday, July 30, 2009 8:51 PM
  • I've taken a look, but being a C# coder, i have not installed VB and couldnt run your app. At first sight all seems done the right way.

    I highly suggest you revise your EDMX and choose plural names for your entity collections as in Category/Categories etc. That might make it easier to see when accessing the collection and the entity itself.

     When you submit changes, are you getting any error ?

    Friday, July 31, 2009 9:32 AM
  • i can do away with the new employee windows and bind the dataform on main administrator page to data source and add new employees... and it works too..

    the only problem is when the data is loaded on to the datagrid the very first row values change according to the the first item on the comboboxes ..though the changes aren't saved on the database.. but it would be confusing for the user to see a changed data in data grid...

    Friday, July 31, 2009 12:32 PM
  • The issue you,re having has to do with INotifyPropertyChanged notification.

    It has good side and bad side to it.

    Good Side:
    Suppose you have a data object bound to multiple forms/lists etc. Say, an Order Status property. By clicking on the Close order button and setting the property to Closed, all the UI interface will update automacticly. That is a nice feature.

    Bad Side:
    So far, the bad side is when you want to Edit your object. You don't want these changes to show until you actually saved your new version of the object. But unfortunately, this is not supported natively by the framework. There is no easy way to deal with this, but it boils down to 1 thing, you have to work on a copy/clone of your data object when editing. Or creating a data object that has 2 views of itsefl. One for display, one for edit (i used this technique once by creating a class that i had all my data object subclass).

    I'm still trying to find a simple viable solution to that problem.

    Friday, July 31, 2009 1:18 PM
  • Here's one structure that could help:

    class YourDataObect -> IEditableObject
       Some Copy Constructor (private for use only by BeginEdit())
       "EditVersion" property which is a Copy of your original
       in IEditableObject.BeginEdit -> Instantiate your Copy (use Copy Contructor)
       in IEditableObject.CancelEdit -> get rid of the copy
       in IEditableObject.EndEdit -> Copy important values back to the original, save it and get rid of your copy.

    For your Edit Form binding, just bind to YourDataObject.EditVersion. while for your lists, bind directly to YourDataObject


    One issue thought is that you must copy values back to the original before you actually save, which means that if the save fails, you will have lost the original values. But maybe this will give you a starter to finding a true solution

    Friday, July 31, 2009 1:46 PM
  • This is the kind of stuff that has me really concerned about this platform right now (Silverlight + Dataform + RIA Services).  I am working on an accounting system with a SQL Server back end for a client.  I made some data entry forms with MS Access and it was totally simple.  I did demo forms with ASP.Net, and it was a little more work, but still pretty straightforward.  The Silverlight forms were much more work and still aren't exactly working correctly.

    I put part of this on myself, I just am learning this new platform and I am still figuring things out.  But it looks like everyone else is in the same boat.  And I really don't think we should be having to go this many hoops to get CRUD forms working the way they should.  Since I do project work for clients and bill hourly, I can't really spend all my time just learning the platform, so we are backing off on the Silverlight UI for now. 

    Hopefully soon there will be improvements in the Dataform and RIA services, as well as some better documentation, then we will come back around to it.  I really do want this platform to succeed and stop developing with the tired old HTML/CSS/javascript stack.  But right now, I don't think all this is really ready for prime time, and my clients would rather stay within budgets than be on bleeding edge technology.

     I will keep on this board though and see how things progress.

    Friday, July 31, 2009 5:19 PM
  • Its been a pretty hard learning curve for me as well. I find myself very frustrated at times, but its great when I finally get things working with this platform.

    Friday, July 31, 2009 5:33 PM
  • I got mine working by putting the DomainDataContext markup inside the stackpanel of my DataTemplate.  I had to do nothing extra.  I think this was because  the components inside the template are not created until runtime and thus do not see the datacontext at all.  It is the same thing as not being able to see the template objects in the codebehind because they are not really there until runtime.

     

    Tuesday, August 04, 2009 11:39 AM
  • I got mine working by putting the DomainDataContext markup inside the stackpanel of my DataTemplate.  I had to do nothing extra.  I think this was because  the components inside the template are not created until runtime and thus do not see the datacontext at all.  It is the same thing as not being able to see the template objects in the codebehind because they are not really there until runtime.

     

    Hiii Can You Be More specific...

    <Noob Me Am>

    Tuesday, August 04, 2009 2:02 PM
  • the only problem is when the data is loaded on to the datagrid the very first row values change according to the the first item on the comboboxes ..though the changes aren't saved on the database.. but it would be confusing for the user to see a changed data in data grid...

    I have exactly the same issue. Has anyone found a good solution for this yet other than working with copies of your data?

    TIA

    Friday, August 28, 2009 11:16 AM
  • the only problem is when the data is loaded on to the datagrid the very first row values change according to the the first item on the comboboxes ..though the changes aren't saved on the database.. but it would be confusing for the user to see a changed data in data grid...

    I have exactly the same issue. Has anyone found a good solution for this yet other than working with copies of your data?

    TIA

    Anyone has a C# sample showing the issue ?

    Friday, August 28, 2009 11:26 AM
  • the only problem is when the data is loaded on to the datagrid the very first row values change according to the the first item on the comboboxes ..though the changes aren't saved on the database.. but it would be confusing for the user to see a changed data in data grid...

    I have exactly the same issue. Has anyone found a good solution for this yet other than working with copies of your data?

    TIA

    We have gotten pretty good at working with copies of data since this thread was active, it is actually a really easy and effective solution now. I have the needed library at my blog here.

    Friday, August 28, 2009 11:29 AM
  • We have gotten pretty good at working with copies of data since this thread was active, it is actually a really easy and effective solution now. I have the needed library at my blog here.

    Thanks Colin, I have read your blog and downloaded the library but I'm not quite sure yet how to apply it in my project.

    My current solution consists of a Web project with some business objects (POCO) + domaincontext and a Silverlight client project, obviously linked with RIA Services. Can you maybe give me some guidelines on what (and where) I need to change my code to have my dataform control bind to copied objects in stead of the original object? Have you got some sample project maybe? Any help is greatly appreciated.

    Thanks!

    Arjan

    BTW keep blogging because we can use all the background information we can get to understand how RIA works Big Smile

    Monday, August 31, 2009 4:55 AM
  • My current solution consists of a Web project with some business objects (POCO) + domaincontext and a Silverlight client project, obviously linked with RIA Services. Can you maybe give me some guidelines on what (and where) I need to change my code to have my dataform control bind to copied objects in stead of the original object? Have you got some sample project maybe? Any help is greatly appreciated.

    One of the examples on my blog is how to do a partial save, the code looks like this:

    PersonDomainContext tempContext = new PersonDomainContext();
    Person savePerson = newPerson();
    tempContext.Persons.Add(savePerson);
    savePerson.ApplyState(originalPerson.ExtractState(ExtractType.OriginalState, ExtractType.ModifiedState);
    tempContext.SubmitChanges();

    To work off of copied data you can use similar code. Have your DataForm bound to a different DomainContext then the main form and move objects back and forth between the two by using the ExtractState and ApplyState methods. In pseuodocode the arrangement lools like this

    Person formPerson = new Person()
    formContext.Persons.Add(formPerson)
    formPerson.ApplyState(originalPerson.ExtractState(ExtractType.OriginalState, ExtractType.ModifiedState)

    //Form makes changes to Person. Now you want to save'

    formContext.SubmitChanges()

    //When the submit comes back successful update the original DomainContext
    originalPerson.ApplyState(formPerson.ExtractState(ExtractType.OriginalState)

    That code works pretty well for single objects. If you have multiple objects you need to copy then look at the Import/Export methods.

    Monday, August 31, 2009 9:28 AM
  • Hi all, I've been struggling to make this work as well and came up with a solution that you can check out on Codeplex: http://referencedataform.codeplex.com/ It's a dataform control that inherits the silverlight toolkit dataform and looks up parent entities on the load of the form. nisbus
    Sunday, October 11, 2009 7:12 AM