c# - Dictionary in CheckListBox help required -


the code c# windows forms application done on visual studio 2012, aim of task use dictionary in gui add, remove, , search books.

i have laid out gui application, contains 4 buttons, 2 textfields, 2 checkboxlists,and few labels explain do.

button3 supposed activate search using isbn. (user enters isbn in textbox1, books contain part of matched)

here form code

dictionary<string, book> library = new dictionary<string, book>(); public form1() {     initializecomponent();     button1.text = "add book";     button2.text = "remove book";     button3.text = "search using isbn";     button4.text = "search using title";     label1.text = "enter isbn below";     label2.text = "enter title below";     label3.text = "tick boxes on left display if book loaned or not";     label4.text = "all books found after search"; }  public void update() {     checkedlistbox1.items.clear();     foreach (var pair in library)     {         checkedlistbox1.items.add(pair.value);     } } private void button1_click(object sender, eventargs e) //add button {     if (textbox1.text != "" && textbox2.text != "")     {         library[textbox1.text] = new book(textbox1.text, textbox2.text);         update();     } } private void button2_click(object sender, eventargs e) //remove button {         library.remove(textbox1.text);         update(); } private void button3_click(object sender, eventargs e) //isbn search button { } 

}

and book class.

class book {     private string isbn;     private string title     private boolean onloan = false;     public book(string isbn, string title)     {         this.isbn = isbn;         this.title = title;     }     public string isbn     {         { return isbn; }         set { isbn = value; }     }     public string title     {         { return title; }         set { title = value; }     }     override public string tostring()     {         return this.isbn + "        " + this.title;     } }  

i struggling button3. enter partial bit of isbn in textbox1, click button, should through dictionary , if finds book matches display them in other checklistbox2.

i have tried quite few methods in displaying them in checklistbox2 when click button nothing appears in checklistbox2.

i'm stumped on how this.

i have tried.

edit:

i have found out going wrong, there nothing wrong logic, sadly form.design.cs did not contain

this.button3.click += new system.eventhandler(this.button3_click); 

i have fixed , works should.

you can use lambda expression

private void button3_click(object sender, eventargs e) //isbn search button {     checkedlistbox2.items.add(_library.first(i => i.key == textbox1.text).value); } 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -