Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Challenge manipulating combobox selectedvalue and selectedvaluechanged

Challenge manipulating combobox selectedvalue and selectedvaluechanged

Scheduled Pinned Locked Moved C#
databasetutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    highjo
    wrote on last edited by
    #1

    Hi! i know people have asked a lot about comboboxes but it's not really about how to get the value or index or whatever.Let me explain.it's users access management application with users, roles and rights: i have a form editRight with 2 combobox cmbUsers to list users and cmbroles to list role of each users and 3 listboxes.let's pause here on load event i fill users combobox with users private void EditRight_Load(object sender, EventArgs e) { try { //Load the user list in the dt_users dataset.dt_users and dt_roles are declare as global variables dt_users = UserManager.FindAll().Tables[0]; //set the combobox cmbUsers datasource cmbUsers.DataSource = dt_users.DefaultView; //set display member and value member cmbUsers.DisplayMember = "user_name"; cmbUsers.ValueMember = "user_id"; CallFillRoleCombo((int)cmbUsers.SelectedValue); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } private void CallFillRoleCombo(int uid) { try { //load users roles into dt_roles database dt_roles = UserRoleManager.FindByUser(uid).Tables[0]; //set combobox datasource cmbroles.DataSource = dt_roles.DefaultView; cmbroles.DisplayMember = dt_roles.Columns[2].ToString(); cmbroles.ValueMember = dt_roles.Columns[1].ToString(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } private void cmbUsers_SelectedValueChanged(object sender, EventArgs e) { CallFillRoleCombo((int)cmbUsers.SelectedValue); } when i run the code its throws exception:Object reference not set to an instance of an object.It seems that its calling the cmbUsers_SelectedValueChanged eventhandler when setting the display member of the cmbUsers combobox. How to work around it?Thank you for reading this.

    eager to learn

    C X H 3 Replies Last reply
    0
    • H highjo

      Hi! i know people have asked a lot about comboboxes but it's not really about how to get the value or index or whatever.Let me explain.it's users access management application with users, roles and rights: i have a form editRight with 2 combobox cmbUsers to list users and cmbroles to list role of each users and 3 listboxes.let's pause here on load event i fill users combobox with users private void EditRight_Load(object sender, EventArgs e) { try { //Load the user list in the dt_users dataset.dt_users and dt_roles are declare as global variables dt_users = UserManager.FindAll().Tables[0]; //set the combobox cmbUsers datasource cmbUsers.DataSource = dt_users.DefaultView; //set display member and value member cmbUsers.DisplayMember = "user_name"; cmbUsers.ValueMember = "user_id"; CallFillRoleCombo((int)cmbUsers.SelectedValue); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } private void CallFillRoleCombo(int uid) { try { //load users roles into dt_roles database dt_roles = UserRoleManager.FindByUser(uid).Tables[0]; //set combobox datasource cmbroles.DataSource = dt_roles.DefaultView; cmbroles.DisplayMember = dt_roles.Columns[2].ToString(); cmbroles.ValueMember = dt_roles.Columns[1].ToString(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } private void cmbUsers_SelectedValueChanged(object sender, EventArgs e) { CallFillRoleCombo((int)cmbUsers.SelectedValue); } when i run the code its throws exception:Object reference not set to an instance of an object.It seems that its calling the cmbUsers_SelectedValueChanged eventhandler when setting the display member of the cmbUsers combobox. How to work around it?Thank you for reading this.

      eager to learn

      C Offline
      C Offline
      Cracked Down
      wrote on last edited by
      #2

      In the following code for loading data in user combobox unsubscribe the event cmbUsers_SelectedValueChanged and after filling data subscribe again

      private void EditRight_Load(object sender, EventArgs e)
      {
      try
      {
      //Load the user list in the dt_users dataset.dt_users and dt_roles are declare as global variables
      dt_users = UserManager.FindAll().Tables[0];
      //set the combobox cmbUsers datasource
      cmbUsers.DataSource = dt_users.DefaultView;
      //set display member and value member
      cmbUsers.DisplayMember = "user_name";
      cmbUsers.ValueMember = "user_id";

      CallFillRoleCombo((int)cmbUsers.SelectedValue);
      }
      }

      hope this works for you!

      1 Reply Last reply
      0
      • H highjo

        Hi! i know people have asked a lot about comboboxes but it's not really about how to get the value or index or whatever.Let me explain.it's users access management application with users, roles and rights: i have a form editRight with 2 combobox cmbUsers to list users and cmbroles to list role of each users and 3 listboxes.let's pause here on load event i fill users combobox with users private void EditRight_Load(object sender, EventArgs e) { try { //Load the user list in the dt_users dataset.dt_users and dt_roles are declare as global variables dt_users = UserManager.FindAll().Tables[0]; //set the combobox cmbUsers datasource cmbUsers.DataSource = dt_users.DefaultView; //set display member and value member cmbUsers.DisplayMember = "user_name"; cmbUsers.ValueMember = "user_id"; CallFillRoleCombo((int)cmbUsers.SelectedValue); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } private void CallFillRoleCombo(int uid) { try { //load users roles into dt_roles database dt_roles = UserRoleManager.FindByUser(uid).Tables[0]; //set combobox datasource cmbroles.DataSource = dt_roles.DefaultView; cmbroles.DisplayMember = dt_roles.Columns[2].ToString(); cmbroles.ValueMember = dt_roles.Columns[1].ToString(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } private void cmbUsers_SelectedValueChanged(object sender, EventArgs e) { CallFillRoleCombo((int)cmbUsers.SelectedValue); } when i run the code its throws exception:Object reference not set to an instance of an object.It seems that its calling the cmbUsers_SelectedValueChanged eventhandler when setting the display member of the cmbUsers combobox. How to work around it?Thank you for reading this.

        eager to learn

        X Offline
        X Offline
        Xmen Real
        wrote on last edited by
        #3

        got your problem try this

        private void cmbUsers_SelectedValueChanged(object sender, EventArgs e)
        {
        if (comboBox2.SelectedValue.GetType() == typeof(int))
        CallFillRoleCombo((int)cmbUsers.SelectedValue);
        }

        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

        1 Reply Last reply
        0
        • H highjo

          Hi! i know people have asked a lot about comboboxes but it's not really about how to get the value or index or whatever.Let me explain.it's users access management application with users, roles and rights: i have a form editRight with 2 combobox cmbUsers to list users and cmbroles to list role of each users and 3 listboxes.let's pause here on load event i fill users combobox with users private void EditRight_Load(object sender, EventArgs e) { try { //Load the user list in the dt_users dataset.dt_users and dt_roles are declare as global variables dt_users = UserManager.FindAll().Tables[0]; //set the combobox cmbUsers datasource cmbUsers.DataSource = dt_users.DefaultView; //set display member and value member cmbUsers.DisplayMember = "user_name"; cmbUsers.ValueMember = "user_id"; CallFillRoleCombo((int)cmbUsers.SelectedValue); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } private void CallFillRoleCombo(int uid) { try { //load users roles into dt_roles database dt_roles = UserRoleManager.FindByUser(uid).Tables[0]; //set combobox datasource cmbroles.DataSource = dt_roles.DefaultView; cmbroles.DisplayMember = dt_roles.Columns[2].ToString(); cmbroles.ValueMember = dt_roles.Columns[1].ToString(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } private void cmbUsers_SelectedValueChanged(object sender, EventArgs e) { CallFillRoleCombo((int)cmbUsers.SelectedValue); } when i run the code its throws exception:Object reference not set to an instance of an object.It seems that its calling the cmbUsers_SelectedValueChanged eventhandler when setting the display member of the cmbUsers combobox. How to work around it?Thank you for reading this.

          eager to learn

          H Offline
          H Offline
          highjo
          wrote on last edited by
          #4

          Thanks guys for replying this post.Really apreciated it.The method that worked for me is the one suggested by deep@Pune.Thanks

          eager to learn

          C 1 Reply Last reply
          0
          • H highjo

            Thanks guys for replying this post.Really apreciated it.The method that worked for me is the one suggested by deep@Pune.Thanks

            eager to learn

            C Offline
            C Offline
            Cracked Down
            wrote on last edited by
            #5

            your most welcome!! :) :) yersterday I forgot to include actual lines in the code to subscribe and unsubscribe the event!! :) soru for that!!!!!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups