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

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

11 Answers 270 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 26 Mar 2013, 06:08 PM
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

11 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 27 Mar 2013, 07:39 AM
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.

0
Michael
Top achievements
Rank 1
answered on 27 Mar 2013, 09:50 AM
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


0
Maya
Telerik team
answered on 27 Mar 2013, 10:59 AM
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.

0
Michael
Top achievements
Rank 1
answered on 27 Mar 2013, 12:25 PM
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


0
Maya
Telerik team
answered on 01 Apr 2013, 11:42 AM
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.

0
Michael
Top achievements
Rank 1
answered on 03 Apr 2013, 10:55 AM
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
0
Michael
Top achievements
Rank 1
answered on 04 Apr 2013, 03:31 PM
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
0
Maya
Telerik team
answered on 08 Apr 2013, 07:20 AM
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.

0
Michael
Top achievements
Rank 1
answered on 08 Apr 2013, 12:30 PM
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
0
Maya
Telerik team
answered on 11 Apr 2013, 07:52 AM
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.

0
Michael
Top achievements
Rank 1
answered on 22 Apr 2013, 01:37 PM
Hello Maya

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

Kind regards,
Michael
Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Maya
Telerik team
Michael
Top achievements
Rank 1
Share this question
or