Hey Community! Happy to be here.
I have a form that contains a custom list control. In this list control, is a flexlayout control called flpListBox with rows of results.
I am having problems catching the click event of each item. I can MessageBox the sender object key (the song name in this case), and that is correct per row clicked, but I want to show the clicked result song name on the parent main form label lblNowPlaying.Text
In ListControl, I have this
And in parent form Form1 I have
The reference for ListControl1.ItemClick correctly refers back, so I don't understand why I can not catch the Song name from the child control, and send to parent form label.
Maybe someone can point me in the right direction, much appreciated
I have a form that contains a custom list control. In this list control, is a flexlayout control called flpListBox with rows of results.
I am having problems catching the click event of each item. I can MessageBox the sender object key (the song name in this case), and that is correct per row clicked, but I want to show the clicked result song name on the parent main form label lblNowPlaying.Text
In ListControl, I have this
C#:
public void Add(string Song, string Artist, string Album)
{
var c = new ListControlItem();
c.Name = "item" + (flpListBox.Controls.Count + 1);
c.Margin = new Padding(0);
c.Song = Song;
c.Artist = Artist;
c.Album = Album;
c.SelectionChanged += SelectionChanged;
c.Click += ItemClicked;
flpListBox.Controls.Add(c);
SetupAnchors();
}
public event ItemClickEventHandler ItemClick;
public delegate void ItemClickEventHandler(object sender, int Index);
private void ItemClicked(object sender, EventArgs e)
{
ListControlItem c = (ListControlItem)sender;
//MessageBox.Show(c.Song);
ItemClick?.Invoke(this, flpListBox.Controls.IndexOfKey(c.Song));
//ItemClick?.Invoke(this, flpListBox.Controls.IndexOfKey((sender as ListControlItem).Song));
}
And in parent form Form1 I have
C#:
InitializeComponent();
ListControl1.ItemClick += new ListControl.ItemClickEventHandler(ListControl1_ItemClick);
C#:
private void ListControl1_ItemClick(object sender, int Index)
{
MessageBox.Show("event caught");
lblNowPlaying.Text = "Now Playing: item index " + Index;
}
The reference for ListControl1.ItemClick correctly refers back, so I don't understand why I can not catch the Song name from the child control, and send to parent form label.
Maybe someone can point me in the right direction, much appreciated