473,405 Members | 2,310 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,405 software developers and data experts.

Listbox doesn't show data

2
I should show this _customers to list box:

Expand|Select|Wrap|Line Numbers
  1. public Customer GetCustomer(int index)
  2.         {
  3.             return (Customer)_customers[index];
  4.  
  5.         }
so I used:
Expand|Select|Wrap|Line Numbers
  1.         private void UpdateCustomerList()
  2.         {
  3.             lstCustomer.Items.Clear();
  4.             for (int index = 0; index <= (_customerMngr.count-1); index++)
  5.                 lstCustomer.Items.Add(_customerMngr.GetCustomer(index).ToString());
  6.  
  7.         }
but my list box doesnt show my data.
how can I convert _customer to string?
Dec 11 '11 #1
3 2657
adriancs
122 100+
Hi, I'm not fully understand what's your situation.

However, base on my understanding of your problem.
The situation that you want to solve might be this:

try this:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace WindowsFormsApplication7
  10. {
  11.     public partial class Form2 : Form
  12.     {
  13.         List<Customer> lstCustomer;
  14.         public Form2()
  15.         {
  16.             InitializeComponent();
  17.             lstCustomer = new List<Customer>();
  18.         }
  19.  
  20.         private void button1_Click(object sender, EventArgs e)
  21.         {
  22.             Customer a = new Customer();
  23.             a.CustomerCode = "A001";
  24.             a.CustomerId = 1;
  25.             a.DateRegister = DateTime.Today;
  26.             a.Name = "John Smift";
  27.  
  28.             Customer b = new Customer();
  29.             b.CustomerCode = "A002";
  30.             b.CustomerId = 2;
  31.             b.DateRegister = DateTime.Today;
  32.             b.Name = "Christina Jess";
  33.  
  34.             lstCustomer.Add(a);
  35.             lstCustomer.Add(b);
  36.         }
  37.  
  38.         private void button2_Click(object sender, EventArgs e)
  39.         {
  40.             if (lstCustomer == null || lstCustomer.Count == 0)
  41.                 return;
  42.             listBox1.Items.Clear();
  43.             for (int i = 0; i < lstCustomer.Count; i++)
  44.             {
  45.                 string c = lstCustomer[i].CustomerId + " - ";
  46.                 c += "(" + lstCustomer[i].CustomerCode + ") ";
  47.                 c += lstCustomer[i].Name;
  48.                 listBox1.Items.Add(c);
  49.             }
  50.         }
  51.     }
  52.  
  53.     public class Customer
  54.     {
  55.         public int CustomerId;
  56.         public string CustomerCode;
  57.         public string Name;
  58.         public DateTime DateRegister;
  59.     }
  60. }
  61.  
Dec 12 '11 #2
If you want the ListBox to display a member in the Customer class (like the customer's name, for instance), you need to override the ToString() method in the Customer class:

Expand|Select|Wrap|Line Numbers
  1. public override string ToString()
  2. {
  3.     return String.Format("{0} {1}", this.FirstName, this.LastName);
  4. }
  5.  
...or something similar.
Dec 13 '11 #3
adriancs
122 100+
to foahchon:
I think you have answered the question.
d^^b
Dec 13 '11 #4

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

Similar topics

3
by: Woodmon | last post by:
Example of my CSS follows: <style type="text/css" media="screen"> BODY { color: white } A:link { color: 66CCFF; } A:visited { color: CC66FF; } A:active { color: CC66FF; } A:hover {...
0
by: Craig Schneider | last post by:
// Is there any way to override the XML Serialization of the following SimpleClass // to turn off the DefaultValue of a boolean? Sure, I can override the DefaultValue from // true to false, but...
7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
5
by: Mark Broadbent | last post by:
Oh yes its that chestnut again! Ive gone over the following (http://www.yoda.arachsys.com/csharp/faq/ -thanks Jon!) again regarding this subject and performed a few of my own tests. I have two...
2
by: Flip | last post by:
In java, the default for methods is override. In c# that is not the case. This talks about two classes, the base class and the overriding class. What happens when you have a third class in the...
5
by: Stoyan | last post by:
Hi All, I don't understand very well this part of MSDN: "Derived classes that override GetHashCode must also override Equals to guarantee that two objects considered equal have the same hash code;...
15
by: John Salerno | last post by:
Hi all. I have a question about virtual and override methods. Please forgive the elementary nature! First off, let me quote Programming in the Key of C#: "Any virtual method overridden with...
2
by: Adriano Coser | last post by:
Hello. After I converted my .net code to the new VC2005 syntax I started to get C4490 on my ExpandableObjectConverter subclass overrides. The GetProperties method is no longer called by the...
8
by: bdeviled | last post by:
I am deploying to a web environment that uses load balancing and to insure that sessions persist across servers, the environment uses SQL to manage sessions. The machine.config file determines how...
5
by: Marcel Hug | last post by:
Hi NG ! I'm new in C# and I'm reading a book about the fundamentals and concepts. In the chapter Methods it's written to use virtual, if i would like to override the method in a subclass. This...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.