winforms - c# - StackOverFlowException when mentioning ListBoxt? -


i'm trying new form (formalbum) open when click buttonopenalbum , have item selected in albumlistbox.

if have in buttonopenalbum_click:

private void buttonopenalbum_click(object sender, eventargs e) {         formalbum musicform = new formalbum(this);         musicform.showdialog(); } 

the new opens without error. however, mention "albumlistbox.selecteditem" (as in code belowin form formmain), "stackoverflowexception unhandled" at:

public listbox albumlistbox {         { // <-this bracket here error highlights 

i don't understand why i'm getting error, must have albumlistbox. doing wrong? appreciated, thank you.

form formmain:

public formmain() {     initializecomponent(); }  private void buttonaddalbum_click(object sender, eventargs e) {     formalbumac addalbumform = new formalbumac(this);     addalbumform.showdialog(); }  private void buttonopenalbum_click(object sender, eventargs e) {     if (albumlistbox.selecteditem != null)     {         messagebox.show(albumlistbox.selecteditem.tostring());         formalbum musicform = new formalbum(this);         musicform.showdialog();     }     else     {         messagebox.show("you need select album list open.");     } }  public static class publicvars {     public static list<album> albumlist { get; set; }      static publicvars()     {         albumlist = new list<album>(max_albums);     } }  public listbox albumlistbox {         {         return albumlistbox;     } } 

look @ property implementation:

public listbox albumlistbox {         {         return albumlistbox;     } } 

it's calling itself, recursively. may easier see if convert method:

public listbox getalbumlistbox() {     return getalbumlistbox(); } 

that's why you've got overflow. it's not clear meant do... did expect value come from? need variable property. did expect set value returned?

i'd strongly discourage design of publicvars class. aside naming, you're using global variables - not idea. work out classes need access data, , how data them appropriately.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -