ComboboxColumn does not update in any Row, except the row beeing edited

12 posts, 0 answers
  1. Michael
    Michael avatar
    15 posts
    Member since:
    Aug 2012

    Posted 26 Mar 2013 Link to this post

    Hello Forum

    I have a RadGridView with two columns. One ComboboxColumn, and one other column. Lets say i have two rows in that grid as well. Whenever i change a value in the Grid, a Calculation is triggered. This calculation can change all the values in my two rows and columns.

    Notice: Changing the value in the ComboboxColumn in Row1 can / does effect the value in the ComboboxColumn in Row2.

    This works fine for all the column types i have tried, except the combobox column. The Combobox will not get updated until i edit a value in the same row, which is too late.

    My ComboboxColumn definition looks like that:

    <telerik:GridViewComboBoxColumn Header="Antriebsart"
         ItemsSourceBinding="{Binding Field[ANTRIEB].ProposedValues}"
         DataMemberBinding="{Binding Field[ANTRIEB].Value}" />

    By searching the documentation and the forums for a solution i have found that there seems to be a difference between ItemsSourceBinding and ItemsSource. Without understanding the difference i have tried using ItemsSource as well, but this did not show any of my "ProposedValues" in the Combobox. Could this be because of the Indexer "Field[ANTRIEB].ProposedValues?

    Additional Info: The Cells not being updated are readonly, i have not tested with "not readonly" cells. But they get updated when i edit another cell in the same row and with other columns, the readonly does not affect (avoid) the update.

    Thanks in advance
    Michael
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 27 Mar 2013 Link to this post

    Hi Michael,

    The difference between ItemsSource and ItemsSourceBinding is that the later (ItemsSourceBinding) should be a collection property from the business object bound to the grid. While in the first case (ItemsSource), it can be from anywhere. The ItemsSource will be one and the same for all items (for the whole column), while ItemsSourceBinding is specific for each item.
    Can you try working with ItemsSource (it needs to be defined in your ViewModel for example) ? Can you try updating the source collections for each object in case you require to work with ItemsSourceBinding ?  

    All the best,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Michael
    Michael avatar
    15 posts
    Member since:
    Aug 2012

    Posted 27 Mar 2013 Link to this post

    Hello Maya

    Thanks a lot for your reply.

    ItemsSource vs. ItemsSourceBinding:
    So, if there is only one ItemsSource per Column (not per Item) i need ItemsSourceBinding. My Comboboxes have different (ItemsSource-) Items in each row.

    ItemsSourceBinding should be Property of the ViewModel bound to the grid:
    You wrote: ItemsSourceBinding should be a collection property from the business object bound to the grid.

    In my case i have a ViewModel- hierarchy like that:
    GridViewModel: Bound to the RadGridView
    --> RowViewModel => (automatically) bound to the GridRows
    ----> CellViewModel (Contains Value, available Values (=> ItemsSource), IsReadOnly and other stuff)

    My ItemsSource is not in the ViewModel Bound to the grid (like you proposed), it is in the CellViewModel. But this seemed to work fine so far. Could it make a difference when it is available from the GridViewModel? I think not, am i wrong with that?

    updating the source collections for each object:
    If i have to do so, i will have to do so. I just wanted to ask if i really, really have to do so ;-)

    Thanks a lot, i will try updating "manually".

    My best wishes,
    Michael


  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 27 Mar 2013 Link to this post

    Hello Michael,

    Actually, it is a bit different than what you posted.
    1. ItemsSource - the source is one and the same for all items - for the whole column.
    So, if your grid is bound to a collection of Players and you have Players and Clubs collections in your ViewModel - you can bind the column to Clubs collection.
    2. ItemsSourceBinding - each data item has its own separate source. In this case your business object - Player - has collection property Clubs - and Clubs is bound through ItemsSourceBinding.
    I would suggest to take a look at this article for a reference as well.

    All the best,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Michael
    Michael avatar
    15 posts
    Member since:
    Aug 2012

    Posted 27 Mar 2013 Link to this post

    Hello Maya

    just 2 more questions:

    1. Where is the difference to my post?
    2. Could this discussion lead to a solution where i do not to have to update manually? I am still not sure if the behavior explained in my first post (not updating comboboxes in all rows) is "by design" or if i am doing something wrong. Please answer this with priority. Because the rest depends on that.
    The article you suggested i have found already, but thanks anyway?

    Michael


  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 01 Apr 2013 Link to this post

    Hi Michael,

    The differences are:
    1. "So, if there is only one ItemsSource per Column (not per Item) i need ItemsSourceBinding." - you need ItemsSourceBinding if you have different sources per item.
    2.  "ItemsSourceBinding should be Property of the ViewModel bound to the grid" - ItemsSourceBinding should be bound to a property from your business object.
    Nevertheless, could you clarify what your exact scenario is, how you update the items and so on? Thus I will be able to create a small sample project based on it.   

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Michael
    Michael avatar
    15 posts
    Member since:
    Aug 2012

    Posted 03 Apr 2013 Link to this post

    Hello Maya

    I just want to know if i do have to update manually the rows not being edited, when using ItemsSourceBinding.

    Kind regards,
    Michael
  8. Michael
    Michael avatar
    15 posts
    Member since:
    Aug 2012

    Posted 04 Apr 2013 Link to this post

    Hello Maya

    You wrote:
    Can you try updating the source collections for each object in case you require to work with ItemsSourceBinding ? 

    I have let the ViewModel send a Message to the view when there needs to be a refresh, so i am in the View now. How would you "update the source collection for each object"? Or, could i do that in the ViewModel aswell?

    Here is my ReceiveMessageMethod in the View with the Grid:

    private void ReceiveCalculationEndedMessage(CalculationEndedMessage msg)
    {
        // here: how to update the source collections?
        // my Grids Name is MainGrid
    }


    Kind regards,
    Michael
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 08 Apr 2013 Link to this post

    Hi Michael,

    Will it be possible to send me a sample project illustrating your exact scenario and settings ? I will update it and send it back to you with the implementation of the update of the source of the items.
    Otherwise, if you have the source of the grid in your ViewModel, you can run through its items and update the source of the combo box column for each of them. However, since I am not aware of your exact architecture, I am only suggesting possible approaches without being sure that they will fit into your requriements.

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Michael
    Michael avatar
    15 posts
    Member since:
    Aug 2012

    Posted 08 Apr 2013 Link to this post

    Hello Maya

    Here is my sample:

    My RadGridView (MainGrid):
    <telerik:RadGridView
    x:Name="MainGrid"
    Grid.Row="1"
    ItemsSource="{Binding SalesLine}"
    SelectedItem="{Binding SelectedLine}"
    AlternationCount="2"
    AlternateRowBackground="AliceBlue">

    My Column:
    <telerik:GridViewComboBoxColumn
    Header="Antriebsart"
    ColumnGroupName="Antriebsart"
    ItemsSourceBinding="{Binding Field[ANTRIEB].ProposedValues}"
    DataMemberBinding="{Binding Field[ANTRIEB].Value}"
    IsVisible="{Binding ColumnVisible[ANTRIEB]}"
    CellStyleSelector="{StaticResource ReadOnlyStyleSelector}"
    Tag="ANTRIEB"
    IsReadOnlyBinding="{Binding FieldIsReadOnly[ANTRIEB]}" />

    Here, in the code behind of the view i would / could do the update:
    private void ReceiveCalculationEndedMessage(CalculationEndedMessage msg)
            {
                // View:
                var myGrid = MainGrid;
                var myColumn = MainGrid.Columns.OfType<GridViewComboBoxColumn>().Where(c => (string) c.Header == "Antriebsart");
      
                // ViewModel:
                var vm = DataContext as EntryLotViewModel;
      
                if (vm == null) return;
                var gridsItemsSource = vm.SalesLine;
      
                // iterating through the Grids ItemsSource
                foreach (var positionViewModel in vm.SalesLine)
                {
                    var comboBoxItemsSource = positionViewModel.Field["ANTRIEB"].ProposedValues;
                    var comboBoxDataMember = positionViewModel.Field["ANTRIEB"].Value;
                    // updating here?
                }
      
                // iterating through the rows of the Grid:
                foreach (var item in myGrid.Items)
                {
                    // ???
                    // or updating here??
                }
            }

    Instead of updating in the view (like above) i could do the update in the ViewModel as well. But from there i won't have any references to the View (MainGrid, Column, ...). I don't know if i need them to perform a proper update. Maybe you can tell me.

    Kind regards,
    Michael
  11. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Apr 2013 Link to this post

    Hello Michael,

    I am attaching a sample project illustrating how you can update the source of column for each item. If it does not correspond to your scenario, could you let me know how it should be updated so that it fits into it ? 

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  12. Michael
    Michael avatar
    15 posts
    Member since:
    Aug 2012

    Posted 22 Apr 2013 Link to this post

    Hello Maya

    Thanks for your help. Finally, updating to 2013.1.403.45 did the job.

    Kind regards,
    Michael
Back to Top