Hi everyone.
i know there is a lot of code and ive reduced it as much as i could,
its a bit much to ask but i am really stuck!
i've been at this for a week! this is converted from vb to c# and
something has gone wrong with the events as the original code used
"WithEvents" and "Handles" keywords.
basically when i debug and get to the mainList_Selected(.............)
method the MainListSelectedEvent is null and i think this is where the
problem is.
if anyone could help id be really greatful!!
This is the main class and this is the method that is called
private void displayHomePage()
{
try
{
Page pg;
while (history.Count > 0)
{
pg = (Page) history.Pop();
pg.Dispose();
}
if (currentPage != null)
{
currentPage.Dispose();
currentPage = null;
}
HomePage newPage = new HomePage();
currentPage = newPage;
MusicXP.frmMain X = this;
newPage.DisplayPage(ref X);
}
catch (System.Exception ex)
{
ErrorHandler.GenericHandler(ex);
}
}
----------------------------------------------------------------------------------------------------------------------------------
public abstract class Page : IDisposable
{
protected dmControls.imageList albumList;
protected dmControls.detailImageList detailList;
protected dmControls.ListControl mainList;
protected dmControls.ListControl sideList;
protected dmControls.VisKeys softKeyboard;
protected frmMain theForm;
protected int albumListSelectedIndex;
protected int detailListSelectedIndex;
protected int mainListSelectedIndex;
protected int sideListSelectedIndex;
protected string hasFocus;
protected string softKeyboardText;
//I took out the main events and delegates that were created in
the conversion, this i think is where the problem
//The MainListSelectedEvent is Null When it is called in the
mainList_Selected.
public delegate void MainListSelectedEventHandler(string
sSelected, object Data);
public MainListSelectedEventHandler MainListSelectedEvent; //=
new MainListSelectedEventHandler(mainList_Selected);
public event MainListSelectedEventHandler MainListSelected
{
add { MainListSelectedEvent =
(MainListSelectedEventHandler)System.Delegate.Comb ine(MainListSelectedEvent,
value); }
remove { MainListSelectedEvent =
(MainListSelectedEventHandler)System.Delegate.Remo ve(MainListSelectedEvent,
value); }
}
public void mainList_Selected(string sSelected, object Data)
{
// object tmpObject = new object();
//Data = tmpObject;
Sounds.PlaySelectSound();
if (MainListSelectedEvent != null)
MainListSelectedEvent(sSelected, Data);
}
"The Rest of the Delegates are in here"
"The Rest of the Event are in here"
public virtual void DisplayPage(ref frmMain myForm)
{
myForm.currentPage = this;
this.albumList = myForm.albumList;
this.detailList = myForm.detailList;
this.mainList = myForm.listNavigation;
this.sideList = myForm.sideNavigation;
this.softKeyboard = myForm.softKeyboard;
this.theForm = myForm;
this.mainList.LeaveControl += new
dmControls.ListControl.LeaveControlEventHandler(ma inList_LeaveControl);
this.mainList.Selected += new
dmControls.ListControl.SelectedEventHandler(mainLi st_Selected);
this.mainList.SelectionChanged += new
dmControls.ListControl.SelectionChangedEventHandle r(mainList_SelectionChanged);
"the Rest of the assignment are in here.............."
}
public Page()
{
}
public void Dispose()
{
this.Dispose();
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------
class HomePage : NavigationPage
{
public HomePage()
{
string[] navArray = new string[6];
navArray[0] = "Recent Albums";
navArray[1] = "Browse All Albums";
navArray[2] = "Browse Artists";
navArray[3] = "Playlists";
navArray[4] = "Scan Music Files";
navArray[5] = "Settings";
base.navArray = navArray;
base.itemCount = navArray.GetLength(0);
//base.mainList.Selected += new
dmControls.ListControl.SelectedEventHandler(mainLi st_Selected);
}
private void HomePage_MainListSelected(string sSelected, object
Data)
{
stuff in here............................
}
public override void SavePageState(ref frmMain myForm)
{
base.SavePageState(ref myForm);
}
public override void DisplayPage(ref frmMain myForm)
{
base.DisplayPage(ref myForm);
myForm.wmp.Visible = true;
myForm.SetUpHomeView();
}
}
}