RadCombobox SelectedIndexChanged fire when program add DataSource property

4 posts, 0 answers
  1. Avelyn Teh
    Avelyn Teh avatar
    10 posts
    Member since:
    May 2010

    Posted 19 Sep 2011 Link to this post

    Dear All,

    I have 2 Radcombox
    Radcombox1 will bind data in Form_Load event  And  Radcombox2 will bind when user selected item at Radcombox1

    This is my code in Form_LoadRadcombox1.NullText = "- Select Name -"
    Radcombox1.DisplayMember = "Name"
    Radcombox1.ValueMember = "ID"
    Radcombox1.DataSource = dataTable
    Radcombox1.SelectedItem = vbNullString

    My problem is when add DataSource to Radcombox1 (Radcombox1.DataSource = dataTable)
    the Radcombox1_SelectedIndexChanged event is fire and it's also binding Radcombox2.

    Please suggest how to make it Binding Radcombox2, only when user selected Item at Radcombox1.

    Thanks and best regards


    *question re-post from TrialUser
  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 21 Sep 2011 Link to this post

    Hi Avelyn Teh,

    Тhis a normal and expected behavior, because the DataSource changed the current position to 0, so the event should be fired. You can workaround this with a BeginUpdate/EndUpdate block:

    Radcombox1.NullText = "- Select Name -"Radcombox1.DisplayMember = "Name" 
    Radcombox1.BeginUpdate() 
    Radcombox1.ValueMember = "ID" 
    Radcombox1.DataSource = dataTable  
    Radcombox1.SelectedItem = vbNullString 
    Radcombox1.EndUpdate()
    I hope it helps. If you have any further questions, do not hesitate to contact me.

    Best wishes,
    Peter
    the Telerik team

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

  3. UI for WinForms is Visual Studio 2017 Ready
  4. NW7US
    NW7US avatar
    6 posts
    Member since:
    Aug 2012

    Posted 07 Aug 2012 Link to this post

    In my scenario, I have a RadComboBox that contains CheckBox items.  I problematically set certain items as Checked, if data exists in a database table.  Here is a segment of code:

    ' now, check anything that is really checked.
     
    Dim idr As Data.DataRow
    Dim ids As Data.DataSet
     
    Dim idt As Data.DataTable
    Dim idtData As New Data.DataSet
     
    Dim iParameters(0 To 0) As Data.SqlClient.SqlParameter
    iParameters(0) = New Data.SqlClient.SqlParameter("@intBIDOID", CheckDBNull(CInt(BIDOID), enumObjectType.IntType))
     
    ids = clsEPD_DATA.StoredGetDataset("spGetBidsSystemTypeNames", iParameters)
     
    If ids.Tables(0).Rows.Count >= 1 Then
        idt = ids.Tables(0)
     
        For Each idr In idt.Rows
     
            ' "BUG" - when one and ONLY one item is check-marked, here, it causes the control to
            ' be in a state as if SelectedIndex has been changed (Telerik states this is expected).
            And, it stays that way, even though we set it here, and the user did NOT change anything. 
            ' This is a "bug" in our scenario, where I must determine if the USER DID THE CHANGE,
            ' not the program.
     
            Dim cboSTObject As RadComboBoxItem = cboSystemType.FindItemByValue(CheckDBNull(idr("SYSTOID"), enumObjectType.IntType))
            cboSTObject.Checked = True
            cboSTObject.Dispose()
     
        Next
     
        ids.Dispose()
     
    End If
     
    '------------ end of System Type checkboxed combobox ----------------------

    Here is the aspx snippet:

    <telerik:RadComboBox ID="cboSystemType" runat="server" Width="200px" EmptyMessage="Select the System Type (if any):"
                                                                        Height="250px" DataTextField="ST_Name" DataValueField="SYSTOID" DataSourceID="SqlDataSource5"
                                                                        TabIndex="8" CheckBoxes="True" CausesValidation="False">
                                                                    </telerik:RadComboBox>
                                                                    <br />
                                                                    <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:EPD_DATAConnectionString %>"
                                                                        SelectCommand="spGetBidSystemTypeNames" SelectCommandType="StoredProcedure">
                                                                    </asp:SqlDataSource>

    What I would like to do is create code such that when my programmatic method changes the index (which appears only to occur when only ONE items is check-marked, but never when zero, or two or more, items are check-marked by the program), that I can somehow set the SelectedIndex code to ignore it, but when the USER MAKES A CHANGE, then I pay attention to it.  Should I create an internal variable "flag" in my program to somehow watch for when I make changes pro grammatically, but clear the flag?  This seems clunky.

    Any guidance would be appreciated.  Thank you.
  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 08 Aug 2012 Link to this post

    Hello Tomas,

    Your question seems to concern RadComboBox for ASP.NET AJAX, while this forum is for RadComboBox for WinForms. If so, please address your question in the ASP.NET AJAX forums: http://www.telerik.com/community/forums/aspnet-ajax/combobox.aspx

    Regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Back to Top