Hi, I'm making a film and entertainment system in a windows form which allows users to select films. I made a custom listbox control which displays a list of films and when the user selects a film, the item in the listbox changes colour. I put this control in the windows form put the code doesnt work, it says that Item and Selected Item haven't been defined?
Heres my code for the custom control:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ColorListBox
{ public partial class ListboxControl : UserControl
{ public ListboxControl()
{ InitializeComponent(); }
private void lbxColour_SelectedIndexChanged(object sender, EventArgs e) { Color namedColor;
String colorName;
colorName = lbxColour.SelectedItem.ToString();
if (colorName != "Black")
{ namedColor = Color.FromName(colorName); }
}
public string NamedColor
{ get { return lbxColour.SelectedItem.ToString(); }
}
private void AddNamedColours()
{ lbxColour.Items.Add("Unknown"); lbxColour.Items.Add("Black");
lbxColour.Items.Add("Blue");
lbxColour.Items.Add("Brown");
lbxColour.Items.Add("Chocolate");
lbxColour.Items.Add("DarkGreen");
lbxColour.SelectedItem = "Blue"; }
protected override void OnPaint(PaintEventArgs e)
{ e.Graphics.DrawRectangle(new Pen(Color.Silver, 2), 0, 0, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1); }
}
}
And heres the code for the windows form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.Win32;
namespace FilmAndEntertainmentSystem
{ public partial class FrmFES : Form
{ static string ta = null;
public FrmFES()
{ InitializeComponent(); }
private void cbxGenre_SelectedIndexChanged(object sender, EventArgs e) { ta = cbxGenre.SelectedItem.ToString();
if (ta == "Action/Thriller")
{ lbxColour.Items.Clear();
lbxColour.Items.Add("CasinoRoyale");
lbxColour.Items.Add("Die Hard");
lbxColour.Items.Add("Raiders of the Lost Ark");
}
else if (ta == "Sci Fi")
{ lbxColour.Items.Clear();
lbxColour.Items.Add("Blade Runner");
lbxColour.Items.Add("Star Wars Trilogy");
lbxColour.Items.Add("Star Trek"); }
}.