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

Need help asap, GridviewComboboxColumn act as a control setting for some unbound column in the radgridview

6 Answers 92 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tai
Top achievements
Rank 1
Tai asked on 11 Dec 2010, 12:58 AM
Hi
plz help me asap if you know because i need to show the demo to client soon .
I am using RIA service and EntityFramework
Thank you

I want to implement a GridViewComboboxColumn which will act as control setting for some unbound column in the radgridview

For example, 
I have a table Account which has two field:
AccountId
PostingId

and the Posting table which has 3 fields:
PostingId
PostingCode
PostingDescription

I want to create a radgridview which has the itemsSource bound to the Account table. The radgridview will have 3 columns
one for AccountId (just a normal textbox column)
one column for PostingId(this one will be the GridViewComboboxColumn because i don't want to display PostingId but i want to display PostingCode).

The tricky thing is the last column. I want to display the PostingDescription corresponding to what has been selected in the PostingId column. And this PostingDescription column is READ ONLY(only for displaying purpose)
Note: the radgridview 's items are Account instances which only has two fields



This is what i am stucking at : 
1. I don't know how to make SelectionChanged event for the GridViewComboboxColumn. I need to know some events which are similar to that one. Because when the event is fired, then i will change the value of the cell PostingDescription correspondingly
2. I don't know how to access the cell value of the PostingId gridViewComboboxColumn and PostingDescription cell. 
I only want to access the correspoding cell of the selected row (not all cells of PostingDescription column)
3. If the account collection has some values, then the radgridview should show all 3 columns value correspondingly. So the 1 is the most important to be implemented

Can you make a sample application to show me how to do that?
simple application without RIA service or Entity Framework is fine. I need to know the necessary methods and functions call to do that

check ur document online and not helpful at all. I think you need to put more comments on the class definition and method and sample example for them


thank you

6 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 11 Dec 2010, 08:15 AM
Hi Tai,

You could use two GridViewComboBoxColumns to achieve such functionality. All you have to do is to bind both columns to the same data source just change DisplayMemberPath property value and make second column read only. I'm attaching a sample project that demonstrates this approach.
Let me know how it works on your end.

Kind regards,
Nedyalko Nikolov
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Tai
Top achievements
Rank 1
answered on 12 Dec 2010, 04:09 AM
Hi NedYalko,

can you tell me where i can look at to know how to :
access the value of the cell in the selected row
For example: in ur sample if the cell of row 1 "Home T-Shirt Color " has been selected . How can i access the value of the cell next to it(or any specific cell in the same row) through the code behind?
(how do we do through the selectionchange event of the combobox ?? or other event??)

I need to know it so i can implement more feature for my radgridview

thank you
0
Tai
Top achievements
Rank 1
answered on 12 Dec 2010, 04:09 AM
Hi NedYalko,

in ur sample, the Color Id column(the last one) only update its value" when the color combobox has been selected a new value and LOST FOCUS of it(by using tab or move to another cell)"

is there anyway to update the value of Color Id column right away when another value of the color combobox has been selected WITHOUT losing focus of the Color combobox cell?

thank you
0
Tai
Top achievements
Rank 1
answered on 13 Dec 2010, 07:42 PM
Hi 

currently, this is my way of implementation for the sample project in order to make the Color Id column update its value right away when the selection change event happen in the Color column

// Adding SelectionChanged event handler for the GridviewComboboxColumn
            this.AddHandler(RadComboBox.SelectionChangedEvent, new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));
            //
// Adding SelectionChanged event handler for the GridviewComboboxColumn
            this.AddHandler(RadComboBox.SelectionChangedEvent, new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));
            //
// Adding SelectionChanged event handler for the GridviewComboboxColumn
            this.AddHandler(RadComboBox.SelectionChangedEvent, new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));
            //
// Adding SelectionChanged event handler for the GridviewComboboxColumn
            this.AddHandler(RadComboBox.SelectionChangedEvent, new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));
            //
 
  //update Description/Control Acct/ Module column right away when the Posting Code combobox items have been selected
       private void comboSelectionChanged(object sender, RadRoutedEventArgs args)
        {
            RadComboBox comboBox = (RadComboBox)args.OriginalSource;
 
            if (comboBox.SelectedValue == null
                || comboBox.DisplayMemberPath != "InsPostingCode1") // we take action only if Posting Code combobox has been changed
                return;
 
            CommissionDetail detail = comboBox.DataContext as CommissionDetail;
            detail.InsPostingCodeId = (int)comboBox.SelectedValue;//we submit the value immediately rather than waiting the cell to lose focus.
        }


However, i kind of don't like this solution because in my screen besides the RadGridview(which has some GridViewComboboxColumns) I also has some normal RadCombobox outside the radgridview. And i don't want the event to fire for those normal Radcombobox(it just does some unnecessary stuff)

Are there anyway to make the event only fire for a particular  GridViewCombobox (in the sample, it is the Color Combobox) inside the RadGridview only? (just like our normal RadCombobox , we can set the SelectionChanged event for a PARTICULAR radcombobox)
0
Tai
Top achievements
Rank 1
answered on 13 Dec 2010, 08:08 PM
hum, i am not mean for spamming my thread . It is just that I think i have figured out the way to set up the SelectionChanged event for a PARTICULAR gridviewComboboColumn in the radgridview and want to share it to other members.

Plz correct me if you have a better implementation for setting the SelectionChanged event for the GridViewComboboxColumn inside the Radgridview because i don't see that event in the list at all

BTW, can you tell me where i can look at to know how to :
access the value of the cell in the selected row
For example: in ur sample if the cell of row 1 "Home T-Shirt Color " has been selected . How can i access the value of the cell next to it(or any specific cell in the same row) through the code behind?
(how do we do through the selectionchange event of the combobox ?? or other event??)

I need to know it so i can implement more feature for my radgridview


in the xaml , i do this

<telerik:GridViewComboBoxColumn DataMemberBinding="{Binding InsPostingCodeId, Mode=TwoWay}" Header="Posting Code"
                                                        ItemsSource="{Binding Source={StaticResource insPostingCodeList},Path=ListofInsPostingCodeWithInclude}"
                                                        DisplayMemberPath="InsPostingCode1" SelectedValueMemberPath="InsPostingCodeId"
                                                
                                                >
                        <telerik:GridViewComboBoxColumn.CellEditTemplate>
                            <DataTemplate>
                                <telerik:RadComboBox SelectedValue="{Binding InsPostingCodeId, Mode=TwoWay}"
                                                        ItemsSource="{Binding Source={StaticResource insPostingCodeList},Path=ListofInsPostingCodeWithInclude}"
                                                        DisplayMemberPath="InsPostingCode1" SelectedValuePath="InsPostingCodeId"
                                                        SelectionChanged="PostingCode_SelectionChanged"
                                                >
                                        <telerik:RadComboBox.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <VirtualizingStackPanel />
                                            </ItemsPanelTemplate>
                                        </telerik:RadComboBox.ItemsPanel>
                                </telerik:RadComboBox>
                            </DataTemplate>
                        </telerik:GridViewComboBoxColumn.CellEditTemplate>
                    </telerik:GridViewComboBoxColumn>


then in the code behind ,

private void PostingCode_SelectionChanged(object sender, SelectionChangedEventArgs e)
       {
           RadComboBox comboBox = sender as RadComboBox;
 
           if (comboBox.SelectedValue == null)
           {
               //if no value has been selected, we won't take any action
               return;
           }
           CommissionDetail detail = comboBox.DataContext as CommissionDetail;
           detail.InsPostingCodeId = (int)comboBox.SelectedValue;//we submit the value immediately rather than waiting the cell to lose focus.
       }
0
Nedyalko Nikolov
Telerik team
answered on 14 Dec 2010, 02:12 PM
Hi Tai,

The solution is very nice and in fact this is the right way to achieve such behavior, but there is one possible problem.
CellTemplate or CellEditTemplate features bypass RadGridView's editing and validation logic, so this solution is not suitable if some business logic validation should be performed on that column.

Regards,
Nedyalko Nikolov
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Tai
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Tai
Top achievements
Rank 1
Share this question
or