Cascading ComboBox in RadGridView retrieving data from SQL

4 posts, 0 answers
  1. Luis Gilbert
    Luis Gilbert avatar
    15 posts
    Member since:
    Jul 2009

    Posted 31 May 2015 Link to this post

    Hi support!

     I have search for cascading comboboxes inside radgridview and found a couple of sample, but all of them use data in class.

    My scenario is different.

    I have 1 radgridview where ItemSource is bind to a SQL table (using LINQ to SQL binding). My table is similar to this:

    - Transaction_Type

    - Customer_ID (GridViewComboBoxColumn1)

    - Invoice_ID (GridViewComboBoxColumn2)

    - Amount

    - User_ID

    So, I want to apply combobox cascading on columns "Customer_ID" and "Invoice_ID". Right now, I am setting Customer_ID.ItemsSource and Invoice_ID.ItemsSource with results from a query I execute on Main_Loaded_Event (I query database asyn via WCF webservice, and then I use these lines to set itemssource:

    ((Telerik.Windows.Controls.GridViewComboBoxColumn)this.GridControl_1.Columns["Account_Invoice_ID"]).ItemsSource = e.Result.metodo_sp_Account_Invoice_SelectResult

     

    So, this specific ItemsSource (Invoice_ID) already contains a "relation" data to Customer.

    The problem is that I can't find how to link both comboboxes..

    I tried to use BeginningEdit event from radgridview to filter the second combobox (Invoice_ID) but this is not working properly. This is what I have:

    ((Telerik.Windows.Controls.GridViewComboBoxColumn)(((Telerik.Windows.Controls.GridView.GridViewCellBase)(e.Cell)).Column)).ItemsSource = Customer_Invoices.Where(x => x.Customer_ID == SelectedCustomerID).

     The problem with this approach, is that while editing a row, this filters ALL rows comboboxes, causing empty results on rows not being edited.

    Is there any sample project for cascading comboboxes in a radgridview when using WCF webservices?

     

    Thanks!

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 02 Jun 2015 Link to this post

    Hi,

    You can find the approach suggested with the CascadingComboboxColumns example available in our SDK Repository. 
    Although GitHub is a very well-known platform we saw a better and easier approach for reviewing our examples developing our SDK Samples Browser. You can install it and use it to search, easily review and edit the examples.

    The idea is to subscribe for the SelectionChanged event of the RadComboBox editor and implement your logic once this happens.
    this.AddHandler(RadComboBox.SelectionChangedEvent, new System.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));
     ...
     
     void comboSelectionChanged(object sender, RoutedEventArgs args)
     {
         RadComboBox comboBox = (RadComboBox)args.OriginalSource;
     
         if (comboBox.SelectedValue == null
             || comboBox.SelectedValuePath != "Code") // we take action only if the continent combo is changed
             return;
     
            //we submit the value immediately rather than waiting the cell to lose focus.
                     ...
     }

    Regards,
    Dimitrina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Luis Gilbert
    Luis Gilbert avatar
    15 posts
    Member since:
    Jul 2009

    Posted 02 Jun 2015 Link to this post

    Hi!

    I am actually using this approach.

    The problem here, is that while editing a row where a specific customer is selected, all other rows shows blank spaces because those rows have a different customer ID value.

    For example, let's say I have 3 rows added:

    - row 1 is for customer A

    - row 2 is for customer B

    - row 3 is for customer A

    If I add row 4, and I select customer C. then all comboboxes in column Customer_ID for row1, row2, row3 shows blank space because itemsource is fixed for all rows (instead of row 4 only).

    Is using property ItemSourceBinding for column "Customer_ID" a solution for my scenario. If so, could you please provide me a sample setting ItemSourceBinding programatically (considering that I am retrieving data from SQL via webservice)?

     

    Thanks!

     

    LMG

  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 03 Jun 2015 Link to this post

    Hi,

    I am not sure if I can understand your requirement right.
    Using ItemsSourceBinding allows binding editor's ItemsSource to a property of the bound data item. That way you can have different sources for the different rows.

    You can also check the article on ComboBox Column to better understand how you should configure the ItemsSourceBinding for GridViewComboBoxColumn and what the difference between ItemsSource and ItemsSourceBinding is. 
    As an example you can check the "ComboBox column items source binding" demo from the SDK Samples Browser. It demonstrates how use GridViewComboBoxColumn with ItemsSourceBinding and FilterMemberPath properties in RadGridView.

    In case the issues still persist, may I ask you to try isolating the case in a demo project illustrating your exact setup? You can also take a look at this blog post for a reference on how to isolate an issue. 
    I would suggest you to open a new support ticket under the respective product category and send the solution there.
     

    Regards,
    Dimitrina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top