Click here to Skip to main content
15,925,602 members
Home / Discussions / C#
   

C#

 
AnswerRe: ADO.NET: DataSet, DataGridView Pin
Jared Parsons1-Dec-05 13:54
Jared Parsons1-Dec-05 13:54 
GeneralRe: ADO.NET: DataSet, DataGridView Pin
budidharma1-Dec-05 14:03
budidharma1-Dec-05 14:03 
GeneralRe: ADO.NET: DataSet, DataGridView Pin
Jared Parsons1-Dec-05 14:17
Jared Parsons1-Dec-05 14:17 
GeneralRe: ADO.NET: DataSet, DataGridView Pin
budidharma1-Dec-05 15:16
budidharma1-Dec-05 15:16 
GeneralRe: ADO.NET: DataSet, DataGridView Pin
budidharma1-Dec-05 15:24
budidharma1-Dec-05 15:24 
GeneralRe: ADO.NET: DataSet, DataGridView Pin
budidharma1-Dec-05 17:06
budidharma1-Dec-05 17:06 
QuestionHelp in Windows Services Via C# Pin
Kariem Soudy1-Dec-05 12:44
Kariem Soudy1-Dec-05 12:44 
AnswerRe: Help in Windows Services Via C# Pin
KaptinKrunch1-Dec-05 18:02
KaptinKrunch1-Dec-05 18:02 
QuestionReferencing form from user control Pin
Dave Hurt1-Dec-05 10:58
Dave Hurt1-Dec-05 10:58 
AnswerRe: Referencing form from user control Pin
Joshua Quick1-Dec-05 12:02
Joshua Quick1-Dec-05 12:02 
GeneralRe: Referencing form from user control Pin
Dave Hurt2-Dec-05 3:49
Dave Hurt2-Dec-05 3:49 
GeneralRe: Referencing form from user control Pin
Joshua Quick2-Dec-05 7:29
Joshua Quick2-Dec-05 7:29 
QuestionFiguring out Installation Location Pin
timothymfox1-Dec-05 10:22
timothymfox1-Dec-05 10:22 
AnswerRe: Figuring out Installation Location Pin
Jared Parsons1-Dec-05 10:31
Jared Parsons1-Dec-05 10:31 
Questiontrouble in loading large xml file Pin
zhujp981-Dec-05 8:18
zhujp981-Dec-05 8:18 
AnswerRe: trouble in loading large xml file Pin
Rob Philpott1-Dec-05 9:10
Rob Philpott1-Dec-05 9:10 
QuestionTips for creating a custom message inbox Pin
mihansen1-Dec-05 7:45
mihansen1-Dec-05 7:45 
QuestionSleep or Wait functions in ASP.NET Pin
TheMajorRager1-Dec-05 7:02
TheMajorRager1-Dec-05 7:02 
AnswerRe: Sleep or Wait functions in ASP.NET Pin
Jared Parsons1-Dec-05 7:46
Jared Parsons1-Dec-05 7:46 
AnswerRe: Sleep or Wait functions in ASP.NET Pin
Colin Angus Mackay1-Dec-05 8:28
Colin Angus Mackay1-Dec-05 8:28 
AnswerRe: Sleep or Wait functions in ASP.NET Pin
Dave Kreskowiak1-Dec-05 10:54
mveDave Kreskowiak1-Dec-05 10:54 
AnswerRe: Sleep or Wait functions in ASP.NET Pin
Reanalyse1-Dec-05 11:43
Reanalyse1-Dec-05 11:43 
QuestionHow to add Event and Delegates to UserControls? Pin
2hdass1-Dec-05 6:41
2hdass1-Dec-05 6:41 
AnswerRe: How to add Event and Delegates to UserControls? Pin
Sean Michael Murphy2-Dec-05 9:41
Sean Michael Murphy2-Dec-05 9:41 
2hdass wrote:
I want this control to act exactly like a normal listbox. I need the ChangedSelectedIndex event on it so that when i click on it in the main program it will do something. Oh, and also i want the button to work too, -- to have a MouseClick event.


You have to bubble the events up. In the user control, wire up the SelectedIndexChanged event of your ListBox and the Click event of the Button to local event handlers like this:
C#
namespace Test {
   public class UserControl1 : System.Windows.Forms.UserControl {
      // Add this to bubble up the listbox event.
      public event EventHandler SelectedIndexChanged;
   
      // Have to rename this event, since "Click" would hide the user
      // control Click event.
      public event EventHandler ButtonClick;
   
      private System.Windows.Forms.ListBox listBox1;
      private System.Windows.Forms.Button button1;
   
      // Windows InitializeComponent() code skipped
   
      public UserControl1() {
         InitializeComponent();
   
         // Wire up the local control events.
         this.listBox1.SelectedIndexChanged += 
                  new System.EventHandler(this.listBox1_SelectedIndexChanged);
         this.button1.Click += new System.EventHandler(this.button1_Click);
      }
   
      private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e) {
         // Raise the event to listeners of your user control 
         if (this.SelectedIndexChanged != null) // Check for subscribers
            this.SelectedIndexChanged(this, e);
      }
   
      private void button1_Click(object sender, System.EventArgs e) {
         // Raise the event to listeners of your user control 
         if (this.ButtonClick != null) // Check for subscribers
            this.ButtonClick(this, e);
      }
   }
}
   
Now the consumers of your control can wire up the new user control events you've exposed, SelectedIndexChanged and ButtonClick, and receive notification of events to the controls that make up your user control.

Share and enjoy.
Sean
QuestionExtracting keys and values from SortedList Pin
smurfy341-Dec-05 5:47
smurfy341-Dec-05 5:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.