Click here to Skip to main content
15,904,638 members
Home / Discussions / C#
   

C#

 
QuestionHow to change the toolbar background color? Pin
Rogenator7-Jul-06 9:17
Rogenator7-Jul-06 9:17 
QuestionPassing variable Pin
Chris McGlothen7-Jul-06 8:23
Chris McGlothen7-Jul-06 8:23 
AnswerRe: Passing variable Pin
Ennis Ray Lynch, Jr.7-Jul-06 8:52
Ennis Ray Lynch, Jr.7-Jul-06 8:52 
GeneralRe: Passing variable Pin
Chris McGlothen7-Jul-06 11:16
Chris McGlothen7-Jul-06 11:16 
AnswerRe: Passing variable Pin
Guffa7-Jul-06 10:59
Guffa7-Jul-06 10:59 
GeneralRe: Passing variable Pin
Chris McGlothen7-Jul-06 11:19
Chris McGlothen7-Jul-06 11:19 
QuestionSent SMTP message via Resent-To headers Pin
mube.co.uk7-Jul-06 7:39
mube.co.uk7-Jul-06 7:39 
QuestionNo update of ListBox after DataSourceChanged Pin
Csharper20067-Jul-06 7:14
Csharper20067-Jul-06 7:14 
Hello!

I am a beginner in UI programming with C#. My problem: I have a ListBox on
a Form, that shall automatically update its content, when the data source
has changed.

I can fire the DataSourceChanged event in the data source class (which is
a derived ArrayList class) and also catch it in the Forms class. But
when I do there a ListBoxInstance.Update() or ...Refresh() ... or
Invalidate(), it has no effect at all. Frown | :(

Maybe someone can give me a hint on what I did wrong?

Here is the interesting part of my source code:


Form1.cs:

        private System.Windows.Forms.ListBox listBox1;<br />
        private System.Windows.Forms.Button button1;<br />
<br />
        // ItemList shall contain the content for the ListBox<br />
         private ItemList itemList = null;<br />
<br />
         public Form1()<br />
         {<br />
            InitializeComponent();<br />
<br />
            itemList = new ItemList();<br />
<br />
            itemList.Add(new Item(1,"One"));<br />
            itemList.Add(new Item(2,"Two"));<br />
            itemList.Add(new Item(3,"Three"));<br />
<br />
            listBox1.DataSource = itemList;<br />
            listBox1.DisplayMember = "Desc";<br />
<br />
            itemList.eventHandler<br />
                += new EventHandler(listBox1_DataSourceChanged);<br />
        }<br />
<br />
        // Is called, when ItemList has changes<br />
        private void listBox1_DataSourceChanged(<br />
            object sender, System.EventArgs e)<br />
        {<br />
            Console.Out.WriteLine("DataSource changed 2");<br />
<br />
            // try all ways to update the list...<br />
            listBox1.Refresh();  // no effect<br />
            Rectangle rect = new Rectangle(new Point(0,0),listBox1.Size);<br />
            listBox1.Invalidate(rect,true); // no effect<br />
            listBox1.Update(); // no effect<br />
        }


Item.cs:
   public class Item<br />
    {<br />
        private int nr;<br />
        private string name;<br />
<br />
        public Item(int a, string b)<br />
        {<br />
            nr = a;<br />
            name = b;<br />
        }<br />
<br />
        public string Desc { get { return "Nr:" + nr + " Name=" + name; } }<br />
   }<br />

ItemList.cs:

     public class ItemList : ArrayList<br />
     {<br />
        public EventHandler eventHandler = null;<br />
<br />
        public ItemList()<br />
        {<br />
        }<br />
<br />
        public void Remove(Item item)<br />
        {<br />
            Console.Out.WriteLine("Soll loeschen: " + item.Desc);<br />
            base.Remove(item);<br />
            FireDataChanged();<br />
        }<br />
<br />
        public void Add(Item item)<br />
        {<br />
            Console.Out.WriteLine("Soll adden: " + item.Desc);<br />
            base.Add(item);<br />
            FireDataChanged();<br />
        }<br />
<br />
        private void FireDataChanged()<br />
        {<br />
<br />
            if (eventHandler != null)<br />
            {<br />
                eventHandler(this,null);<br />
            }<br />
        }<br />
     }


When I call the methods Add or Remove in ItemList, the event is fired,
I can see the Console.out.WriteLine-Message, but the ListBox is not
updated...

Thanks for help Smile | :)
AnswerI think it is a VS bug Pin
Ennis Ray Lynch, Jr.7-Jul-06 8:15
Ennis Ray Lynch, Jr.7-Jul-06 8:15 
GeneralRe: I think it is a VS bug Pin
Josh Smith7-Jul-06 8:27
Josh Smith7-Jul-06 8:27 
GeneralThat makes sense Pin
Ennis Ray Lynch, Jr.7-Jul-06 8:35
Ennis Ray Lynch, Jr.7-Jul-06 8:35 
QuestionText Won't Show in MessageBox Pin
MartyExodus7-Jul-06 5:46
MartyExodus7-Jul-06 5:46 
AnswerRe: Text Won't Show in MessageBox Pin
Jun Du7-Jul-06 6:17
Jun Du7-Jul-06 6:17 
GeneralRe: Text Won't Show in MessageBox Pin
MartyExodus7-Jul-06 6:30
MartyExodus7-Jul-06 6:30 
JokeRe: Text Won't Show in MessageBox Pin
BoneSoft7-Jul-06 7:27
BoneSoft7-Jul-06 7:27 
AnswerRe: Text Won't Show in MessageBox Pin
Josh Smith7-Jul-06 8:29
Josh Smith7-Jul-06 8:29 
GeneralRe: Text Won't Show in MessageBox [modified] Pin
MartyExodus7-Jul-06 9:14
MartyExodus7-Jul-06 9:14 
GeneralRe: Text Won't Show in MessageBox Pin
Rogenator7-Jul-06 9:25
Rogenator7-Jul-06 9:25 
GeneralRe: Text Won't Show in MessageBox Pin
MartyExodus7-Jul-06 10:05
MartyExodus7-Jul-06 10:05 
GeneralRe: Text Won't Show in MessageBox [modified] Pin
Rogenator7-Jul-06 11:15
Rogenator7-Jul-06 11:15 
AnswerRe: Text Won't Show in MessageBox Pin
cje7-Jul-06 11:51
cje7-Jul-06 11:51 
GeneralRe: Text Won't Show in MessageBox Pin
MartyExodus11-Jul-06 9:24
MartyExodus11-Jul-06 9:24 
GeneralRe: Text Won't Show in MessageBox Pin
Dustin Metzgar11-Jul-06 9:50
Dustin Metzgar11-Jul-06 9:50 
QuestionDrawing on Map Pin
Sandy Saroha7-Jul-06 4:51
Sandy Saroha7-Jul-06 4:51 
AnswerRe: Drawing on Map Pin
Jun Du7-Jul-06 5:17
Jun Du7-Jul-06 5:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.