Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > ComboBox and ListBox (obsolete as of Q2 2010) > combbobox selectedvaluechanged event not working

Not answered combbobox selectedvaluechanged event not working

Feed from this thread
  • srm avatar

    Posted on Jul 18, 2011 (permalink)

    I am building an application where users r coming from database in combobox on combobox1_Enter event.
    I am also populating from another table rights for the particular user as per
    selectedvaluechanged event of the same comboobx in datagridview.The problem comes when I reselect
    same user error is"object not set to an instance of an object" this does not happen if I click buton for
    populating usersrights in gridview when i select value in combobox.Can anybody help me with this?
    here is the code:
    private void UsersCombox_Enter(object sender, EventArgs e)
            {
                ds = null;
                UsersCombox.SelectedIndex = -1;
                SqlConnection mycon = new SqlConnection("Data source=DOTNET1;integrated security=true;initial catalog=examcollectiondata");
                SqlDataAdapter adap = new SqlDataAdapter("select * from createuserTbl", mycon);
                ds = new DataSet();
                adap.Fill(ds, "createusertbl");
                UsersCombox.DataSource = ds;

                UsersCombox.ValueMember = "CreateUserTbl.UserName";

                ds.AcceptChanges();


                ds.GetChanges();
                UsersCombox.Refresh();
            }

    private void UsersCombox_SelectedValueChanged(object sender, EventArgs e)
            {
               //error when reselecting value in combobox
                SqlConnection mycon = new SqlConnection("data source=dotnet1;initial catalog=ExamCollectionData;integrated security=true");
    //error comes in the line below
                SqlDataAdapter adap = new SqlDataAdapter("select DiffForms,selectdata,insertdata,updatedata,deletedata,viewreports from useraccesstbl where users='" + UsersCombox.SelectedValue.ToString() + "'", mycon);

                DataSet ds = new DataSet();
                adap.Fill(ds, "useraccesstbl");

                dataGridView1.DataSource = ds;
                dataGridView1.DataMember = "useraccesstbl";

    Reply

  • Peter Peter admin's avatar

    Posted on Jul 21, 2011 (permalink)

    Hi Srm,

    Thank you for writing.

    I can suppose that in this line
    select DiffForms,selectdata,insertdata,updatedata,deletedata,viewreports from useraccesstbl where users='" + UsersCombox.SelectedValue.ToString()
    the SelectedValue is Null.

    I would like to suggest to execute the SQL statement only if SelectedValue is not null.
    You also can use the SelectedIndexChanged event instead of SelectedValueChanged event and check if the SelectedIndex is bigger than -1.

    I hope this helps.

    Kind regards,
    Peter
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > ComboBox and ListBox (obsolete as of Q2 2010) > combbobox selectedvaluechanged event not working
Related resources for "combbobox selectedvaluechanged event not working"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]