0

I don't know how to register event that happened inside of user control in my form. Form has 3 FloatLayoutPanels Each FloatLayoutPanel has list of UserControls. Each UserControl has ComboBox I would like to be able to move UserControls between FloatLayoutPanels on ComboBox onvaluechanged event. In order to do that I would need to register that event from UserControl ComboBox happened in the main form

Here is my UserControl constructor:

public event EventHandler SelectedStatusValueChanged;


public ucNarudzba()
    {
        InitializeComponent();
        this.cmbPromjenaStanja.SelectedValueChanged += new System.EventHandler(this.cmbPromjenaStanja_SelectedValueChanged);
    }

this is my combobox SelectedValueChanged event

 private void cmbPromjenaStanja_SelectedValueChanged(object sender, EventArgs e)
    {
        if (SelectedStatusValueChanged != null)
            SelectedStatusValueChanged(sender, e);
    }

Then in my form I should access event something like this (not sure if this is correct)

private void ucNarudzba_SelectedStatusValueChanged(object sender, EventArgs e)
    {
        // Do what I want
        
    }

and if it is correct I dont know how to write code in form's designer.cs file that would call this event!

So I am asking for feedback if this is ok method to get event data from user control to form, and help with calling event from form's designer.cs file.

Any help is appreciated!!!!

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
sasko
  • 207
  • 2
  • 20
  • Suggested googling and reading: **[What is the preferred way to bubble events](https://stackoverflow.com/questions/4349195/what-is-the-preferred-way-to-bubble-events)** Several hundred thousand other posts here as well – Ňɏssa Pøngjǣrdenlarp Aug 01 '21 at 23:12

1 Answers1

2

did u add this line to your form UserControl1.SelectedStatusValueChanged += new EventHandler(ucNarudzba_SelectedStatusValueChanged);

Jason N
  • 109
  • 3