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. How to create a method in a User control

How to create a method in a User control

Scheduled Pinned Locked Moved C#
databasehelptutorialquestion
11 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.
  • I Offline
    I Offline
    Ismael_1999
    wrote on last edited by
    #1

    Hi. I created a user control which has a textbox and a combobox. Depending on the state of the screen (navigation, creation or editing) one of them is visible and the other is invisible. This user control works with a database. Now what I need is to create a method for this component which should work the same way as the SelectedItemChanged of the combobox. Can anyone help me? Thanks.

    M R 2 Replies Last reply
    0
    • I Ismael_1999

      Hi. I created a user control which has a textbox and a combobox. Depending on the state of the screen (navigation, creation or editing) one of them is visible and the other is invisible. This user control works with a database. Now what I need is to create a method for this component which should work the same way as the SelectedItemChanged of the combobox. Can anyone help me? Thanks.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      It would help to know what UI you are using.

      Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

      I 1 Reply Last reply
      0
      • I Ismael_1999

        Hi. I created a user control which has a textbox and a combobox. Depending on the state of the screen (navigation, creation or editing) one of them is visible and the other is invisible. This user control works with a database. Now what I need is to create a method for this component which should work the same way as the SelectedItemChanged of the combobox. Can anyone help me? Thanks.

        R Offline
        R Offline
        Ralf Meier
        wrote on last edited by
        #3

        It would also help if you describe what EXACTLY should happen. I suppose you are using FORMS. Perhaps ... basicly you should take a look to the functionality of Events ... that could be a way for you ...

        I 1 Reply Last reply
        0
        • R Ralf Meier

          It would also help if you describe what EXACTLY should happen. I suppose you are using FORMS. Perhaps ... basicly you should take a look to the functionality of Events ... that could be a way for you ...

          I Offline
          I Offline
          Ismael_1999
          wrote on last edited by
          #4

          Hi Ralf and thanks for your interest. I’m using C# in Visual Studio and this application is in forms. The component I’ve created is composed of a TextBox and a ComboBox. For example, suppose the main table is Sales and the secondary tables are Client [CodCli(integer, PK), NameCli(string)] and PayForm [CodPay(integer, PK), DescPay(string)]. In the table Sales, suppose the fields are: NumSale (integer, PK), CodCli (FK for Client), CodPay (FK for PayForm), Price and Date. Suppose there’s a Grid that shows data from the main table and data related to the other tables. See figure below. (Sorry, but I coudn't post an image. I'm trying and if I can, you'll see it). So, when in navigating mode, this is what we see. When you click a register in the grid, the fields below are updated to show the corresponding data. When you click the Create button (+), both fields Cliente and Forma de Recebimento become Comboboxes so you can choose the client and the pay form. Data are retrieved from the corresponding tables (datasource). The other fields become empty. When you click the edit button (pencil), those fields also become comboboxes, but all fields show the data of the grid. The component I’ve made is working fine for all of this. My problem is: in create or edit mode, when I select the client, it’s necessary to select the pay forms allowed for that client (cash, credit card or others), which are in another relation table, so to fill the second combobox. If it were a simple combobox, it would be easy: use the SelectedIndexChanged event. But, as the combobox is now part of a User control, I don’t know how to do this. If you need any more information, let me know. Can you help me?

          R 1 Reply Last reply
          0
          • M Mycroft Holmes

            It would help to know what UI you are using.

            Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

            I Offline
            I Offline
            Ismael_1999
            wrote on last edited by
            #5

            Hi, Mycroft (nice name). Please see the answer to Ralf, in this same post. Thank you.

            1 Reply Last reply
            0
            • I Ismael_1999

              Hi Ralf and thanks for your interest. I’m using C# in Visual Studio and this application is in forms. The component I’ve created is composed of a TextBox and a ComboBox. For example, suppose the main table is Sales and the secondary tables are Client [CodCli(integer, PK), NameCli(string)] and PayForm [CodPay(integer, PK), DescPay(string)]. In the table Sales, suppose the fields are: NumSale (integer, PK), CodCli (FK for Client), CodPay (FK for PayForm), Price and Date. Suppose there’s a Grid that shows data from the main table and data related to the other tables. See figure below. (Sorry, but I coudn't post an image. I'm trying and if I can, you'll see it). So, when in navigating mode, this is what we see. When you click a register in the grid, the fields below are updated to show the corresponding data. When you click the Create button (+), both fields Cliente and Forma de Recebimento become Comboboxes so you can choose the client and the pay form. Data are retrieved from the corresponding tables (datasource). The other fields become empty. When you click the edit button (pencil), those fields also become comboboxes, but all fields show the data of the grid. The component I’ve made is working fine for all of this. My problem is: in create or edit mode, when I select the client, it’s necessary to select the pay forms allowed for that client (cash, credit card or others), which are in another relation table, so to fill the second combobox. If it were a simple combobox, it would be easy: use the SelectedIndexChanged event. But, as the combobox is now part of a User control, I don’t know how to do this. If you need any more information, let me know. Can you help me?

              R Offline
              R Offline
              Ralf Meier
              wrote on last edited by
              #6

              Hi ... you wrote a very complete description ... but (sorry) I didn't understood the problem you have. Perhaps the reason is because I can't see what you are doing ... A question : where is the real problem when you try to include it to the UserControl ? At the beginning I thought that you don't have any experience with Events - my mistake. I suppose that you also don't have a problem to include a method to the UserControl. I suppose that you problem is to access the data which is "outside" the UserControl (perhaps part of the Form) ? Please write something more - not only for me ...

              I 1 Reply Last reply
              0
              • R Ralf Meier

                Hi ... you wrote a very complete description ... but (sorry) I didn't understood the problem you have. Perhaps the reason is because I can't see what you are doing ... A question : where is the real problem when you try to include it to the UserControl ? At the beginning I thought that you don't have any experience with Events - my mistake. I suppose that you also don't have a problem to include a method to the UserControl. I suppose that you problem is to access the data which is "outside" the UserControl (perhaps part of the Form) ? Please write something more - not only for me ...

                I Offline
                I Offline
                Ismael_1999
                wrote on last edited by
                #7

                Hi, Ralf. And thank you again for trying to help me. My component is already accessing the external data, without problem. The fact is that I don’t know how to create the event. In fact I know how to create an event, but I don't know how to associate it to the click of the user in selecting a client: I need to create an event in the User Control that triggers when the user selects a client in the combobox. I suppose it would be similar to the SelectedIndexChange that exists in the combobox. Could you help me to do this? If you need any information, please let me know. And thanks again.

                R 1 Reply Last reply
                0
                • I Ismael_1999

                  Hi, Ralf. And thank you again for trying to help me. My component is already accessing the external data, without problem. The fact is that I don’t know how to create the event. In fact I know how to create an event, but I don't know how to associate it to the click of the user in selecting a client: I need to create an event in the User Control that triggers when the user selects a client in the combobox. I suppose it would be similar to the SelectedIndexChange that exists in the combobox. Could you help me to do this? If you need any information, please let me know. And thanks again.

                  R Offline
                  R Offline
                  Ralf Meier
                  wrote on last edited by
                  #8

                  Hi again, in fact it is a problem for me to understand where you stuck. You know how to work with Events ? If Yes : the SelectedIndexChanged-Event would be useful for you ? So : because the Combobox is part of your UserControl the Eventhandler-method from the Combobox must also be part of the UserControl. Did you realized it like that ? If Yes : where exactly is your problem ? You have assigned this method to the Event of the Combobox ? My problem at this point is that I don't know anything about your knowledge and/or experience. Perhaps my questions are to low in their level ... or at the right point - i don't know. So it's your turn to help me to help you ...

                  I 1 Reply Last reply
                  0
                  • R Ralf Meier

                    Hi again, in fact it is a problem for me to understand where you stuck. You know how to work with Events ? If Yes : the SelectedIndexChanged-Event would be useful for you ? So : because the Combobox is part of your UserControl the Eventhandler-method from the Combobox must also be part of the UserControl. Did you realized it like that ? If Yes : where exactly is your problem ? You have assigned this method to the Event of the Combobox ? My problem at this point is that I don't know anything about your knowledge and/or experience. Perhaps my questions are to low in their level ... or at the right point - i don't know. So it's your turn to help me to help you ...

                    I Offline
                    I Offline
                    Ismael_1999
                    wrote on last edited by
                    #9

                    Hi, Ralf. I think I coudn't explain exactly my doubts. But in another forum I found the answer to my questions and I was able to finish my component. If you are interested, the article is: c# - Call SelectedIndexChanged on ComboBox within User Control - Stack Overflow[^] There I could see how I can make the Combobox SelectedIndexChanged event available to the user control. And once again, thanks for your efforts to help me.

                    R 1 Reply Last reply
                    0
                    • I Ismael_1999

                      Hi, Ralf. I think I coudn't explain exactly my doubts. But in another forum I found the answer to my questions and I was able to finish my component. If you are interested, the article is: c# - Call SelectedIndexChanged on ComboBox within User Control - Stack Overflow[^] There I could see how I can make the Combobox SelectedIndexChanged event available to the user control. And once again, thanks for your efforts to help me.

                      R Offline
                      R Offline
                      Ralf Meier
                      wrote on last edited by
                      #10

                      OK ... if it is realized ... But exactly that was the thing I supposed ... We could get there here ... if you answered my last questions ...

                      I 1 Reply Last reply
                      0
                      • R Ralf Meier

                        OK ... if it is realized ... But exactly that was the thing I supposed ... We could get there here ... if you answered my last questions ...

                        I Offline
                        I Offline
                        Ismael_1999
                        wrote on last edited by
                        #11

                        Right,Ralf. Yes. I think you are right. You had helped me some times. I appreciate that. I wish you luck.

                        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