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

RadGridView ComboBox filled with different Data

5 Answers 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Oscar
Top achievements
Rank 1
Oscar asked on 10 Nov 2011, 04:33 AM
Hello

I have a RadGridview, one of those columns is a GridViewComboBoxColumn
 
<telerik:GridViewComboBoxColumn Header="Manager"
SelectedValueMemberPath="EmployeeId"
DataMemberBinding="{Binding ManagerEmployeeId, Mode=TwoWay}"
DisplayMemberPath="Name"
UniqueName="Manager"
/>



The RadGridView is bound to the Employees ( with a nice MVVM implementation), Employees has many fields like EmployeeID, Name, Address, Phone, etc and there are columns on the RadGridView for them.. one of those columns is a ComboBox to allow the selection of manager for each employee. The manager is also an employee, therefore the ManagerColumnComboBox is populated with Employee table.  

I am able to populate the  GridViewComboBoxColumn with Employees data, but I need to exclude “self-employee” from the collection, because obviously the employee cannot be his/her own manager. so there is only one table involved, the Employee data populates the RadGridView and also the populates the ManagerComboBoxColum in inside that RadGridView.

I have tried may approaches, with no luck.

Let say I have 20 Employees , only 19 of them can be his/her manager, all but him/her self.

How can I populate the ComboBox column for the data grid with the Candidate managers (excluding the current employee on each row).

Sorry for the long explanation, but I think is necessary

Thanks
:)


5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 10 Nov 2011, 08:40 AM
Hi Oscar,

You can try to work with ItemsSourceBinding of  GridViewComboBoxColumn thus defining a specific source for each item. Please take a look at our online documentation for further reference. 
Will that approach suit your needs ?

Best wishes,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Oscar
Top achievements
Rank 1
answered on 10 Nov 2011, 06:08 PM
Thank you Maya. Like always, Telerik answers are very fast and very good

But I need an event to fire to allow me do the magic.

For example I tried the RowLoaded , SelectionChanged to allow me get the right data for each ComboBoxColumn

I am looking for the right event.
Something to fire every time a GridViewComboBoxColumn is created , I will filter the data, and then assigned to the ComboBox

((GridViewComboBoxColumn)MyGrid.Columns["MyColumn"]).ItemsSource =  collectionOfEmployeesWithCurrentEmployeeRemoved
 
or something.

Can you help me :)
0
Oscar
Top achievements
Rank 1
answered on 10 Nov 2011, 06:37 PM
see, this seems to do the trick, but the problem is that when i select the Manager GridComboBoxColumn. all the Rows for that Column  get updated/refreshed , i wish just to update the one Cell i am selecting

public Employee CurrentEmployee { get; set; }
public int CurrentEmployeeId { get; set; }
private void EmployeesGrid_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
{
    var selectedSource = e.OriginalSource as Telerik.Windows.Controls.DataControl;
    if (selectedSource != null)
    {
        var theItem = selectedSource.SelectedItem;
        CurrentEmployee = (Employee)theItem;
        CurrentEmployeeId = CurrentEmployee.EmployeeId;
        ((GridViewComboBoxColumn)EmployeesGrid.Columns["Manager"]).ItemsSource = CollectionOfEmployeesWithCurrentEmployeeRemoved;
    }
}

Regards
0
Oscar
Top achievements
Rank 1
answered on 11 Nov 2011, 03:56 PM
I also tried putting the code on the   Preparing Cell For Edit event
public int CurrentEmployeeId { get; set; }
private void PreparingCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
{
    Employee EmployeeModel = e.EditingElement.DataContext as Employee;
    if (EmployeeModel != null)
    {
        CurrentEmployeeId = EmployeeModel.EmployeeId;
        ((GridViewComboBoxColumn)EmployeesGrid.Columns["Manager"]).ItemsSource = Managers.EmployeeManager.RetrieveManagerEmployees(CurrentEmployeeId);
    }
     
}

The filter works, but all Columns on the RadGridView get refreshed when I select the combobox cell to change the Manager on each Employee Row

Any suggestions ?
0
Maya
Telerik team
answered on 11 Nov 2011, 05:04 PM
Hi Oscar,

Generally, you cannot remove an item from the source of the column expecting it to be available in the source for the other items (as it is here - to remove a 'Manager' from the source of the corresponding item and to display it as a possible choice for the other items in the grid). If you do not want to use ItemsSourceBinding, you can try to disable the 'Manager' value. Please take a look at this forum thread and the sample attached there (DisabledItemsInCombo-WPF.zip). It targets WPF, but still the idea is the same.
Will that approach suit your needs ? 

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Oscar
Top achievements
Rank 1
Answers by
Maya
Telerik team
Oscar
Top achievements
Rank 1
Share this question
or