RadGridView ComboBox filled with different Data

6 posts, 0 answers
  1. Oscar
    Oscar avatar
    25 posts
    Member since:
    Aug 2012

    Posted 09 Nov 2011 Link to this post

    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
    :)


  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 10 Nov 2011 Link to this post

    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 >>

  3. Oscar
    Oscar avatar
    25 posts
    Member since:
    Aug 2012

    Posted 10 Nov 2011 Link to this post

    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 :)
  4. Oscar
    Oscar avatar
    25 posts
    Member since:
    Aug 2012

    Posted 10 Nov 2011 Link to this post

    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
  5. Oscar
    Oscar avatar
    25 posts
    Member since:
    Aug 2012

    Posted 11 Nov 2011 Link to this post

    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 ?
  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Nov 2011 Link to this post

    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 >>

Back to Top