473,396 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to handle lstbox values

7
Hello C# Programmers, here is my question and problem. I am practicing my C# skills, and designed a simple GUI app for a library. Well, I have the class Member, and a button Search, user types the member code in a textbox, my program gets the value and finds the member in the list of "signed" members, else throws a fancy message box. Everything is fine, my problem is, a member does a Loan from library clicking the New Loan button, and within the code :
Expand|Select|Wrap|Line Numbers
  1.  
  2. public MainWindow()
  3. {
  4. lstLoans.ItemsSource = loans;
  5. }
.loans is not in the Member class, it is a field of the class MainWindow, Member class has it's own loans private field and Loans property that gets the loans returned.
My problem is, if I type another member code as "user" of the program and press Search, it gets me the new member.Name,..etc , but I have in my mind that each Member is a different instance. But when i press Search button and I Change Member, current loans from the previous and all members are visible to lstLoans,
I want somehow, clearing the list when I get another member and also to show only this members Loans to the lstLoans, and not all loans done.
If you need any code inform me, or just reply ideas.

Thanks in advance.
May 4 '11 #1
2 1353
Vagos
7
Hello again, I am replying in order to post a part of my code, so maybe you can understand what i ask for.
Here is a part of the MainWindow code:
Expand|Select|Wrap|Line Numbers
  1. public partial class MainWindow : Window
  2.     {
  3.         List<Member> members;
  4.         Member member;
  5.         ObservableCollection<Loan> loans;
  6.  
  7.         public MainWindow()
  8.         {
  9.             InitializeComponent();
  10.             members = GetMembers();
  11.  
  12.             //member = GetMember(textBox1.Text); 
  13.             loans = new ObservableCollection<Loan>();
  14.             List<Title> titles = GetAllTitles();
  15.  
  16.             //DataContext = member;
  17.             lstTitles.ItemsSource = titles;
  18.             lstLoans.ItemsSource = loans;
  19.         }
  20.  
Here is a delete loan button :
Expand|Select|Wrap|Line Numbers
  1. private void btnDeleteLoan_Click(object sender, RoutedEventArgs e)
  2.         {
  3.             try
  4.             {
  5.                 Loan selectedLoan = (Loan)lstLoans.SelectedItem;
  6.  
  7.                 if (selectedLoan == null)
  8.                     throw new NoMoreTitlesLoanedException(member.Name);
  9.  
  10.                 selectedLoan.Return();
  11.                 member.RemoveLoan(selectedLoan);
  12.                 //selectedLoan.Member.Loans.Remove(selectedLoan);
  13.                 loans.Remove(selectedLoan);
  14.                 //lstLoans.ItemsSource = loans;
  15.             }
  16.             catch (NoMoreTitlesLoanedException nml)
  17.             {
  18.                 MessageBox.Show(nml.ToString());
  19.             }
  20.         }
  21.  
Here is the code for search button :
Expand|Select|Wrap|Line Numbers
  1.         /// <summary>
  2.         /// Enter a code and press Search to find the member
  3.         /// </summary>
  4.         /// <param name="sender"></param>
  5.         /// <param name="e"></param>
  6.         private void btnSearch_Click(object sender, RoutedEventArgs e)
  7.         {
  8.             try
  9.             {
  10.                 Member foundMember = null;
  11.                 foundMember = GetMember(textBox1.Text.ToUpper());
  12.  
  13.                 if (foundMember == null)
  14.                     throw new MemberNotFoundException(textBox1.Text); 
  15.  
  16.                 member = foundMember;
  17.                 DataContext = member;
  18.             }
  19.             catch (MemberNotFoundException mnf)
  20.             {
  21.                 MessageBox.Show(mnf.ToString());
  22.             }
  23.         }
  24.  
Now, what I want is, when the member code changes, by the search button I guess, the lstLoans box to show the specific member loans only, and not all loans done so far.

Thanks in advance.
May 7 '11 #2
bvrwoo
16
If you only want the the 1st showing up then you have to clear the list and set only the item as the source if you are displaying only one, else you will see them all inserted into the list hence the name data source. You have the observablecollection right but when you bind data from a list, the whole list is inserted.
Aug 29 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Grant Edwards | last post by:
Perhaps I'm doing something wrong: the struct module docs say it's IEE 754, but I can't figure out how to get it to handle NaN values correctly (either packing or unpacking). >>> x =...
3
by: lee | last post by:
Hello I need some javascript code I've written to handle 2 values from an HTML form. I've been successful using the "label" attribute (I've simplied the example below): <input type="radio"...
2
by: Mark Heimonen | last post by:
I haven't worked with enum types that much, and I wrote the following code to bind a list of enums to a dropdownlist. Using CType(.Parse(GetType(ManagePointClassLibrary.Utils.Log.EventType),...
11
by: eddy de boer | last post by:
Hello, in my aspx page I have the followong code: <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> .... <%# Server.HtmlDecode((string)DataBinder.Eval(Container.DataItem,"tekst"))...
0
by: Jason Coyne | last post by:
Here is another programming blog entry. Sorry for the normal friends :) I recently ran into a problem with a web service I was trying to call from c# where the web service returned null dates...
3
by: psycho | last post by:
how should i hanle null values returned by the datareader i am using OleDbDataReader for accessing access database.
5
by: tonialbrown | last post by:
I have some code that updates a record's fields based on a selection from a list box (lstDelFrom). The user selects the record from the list box & it copies it into the fields , , etc. My...
2
by: Will | last post by:
Hi, I need to handle blank values in a query calculation. I have 636 records at the moment but when I sum over these records the blank fields are not returned. I have looked around here and on...
1
by: apache626 | last post by:
I really need help with this one. I am using a script task to write data pulled from a MS SQL DB to a fixed width file. The script takes the ItemArray and writes the value of the column to the file...
1
by: NareshN | last post by:
Hi, I am using this stored procedure with pivot.If i dont have data i am getting null with this stored procedure.Can u tell me how to handle null.below query is pivot. I am using like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.