Click here to Skip to main content
15,881,812 members
Home / Discussions / Windows Forms
   

Windows Forms

 
GeneralRe: ListBox does not update when DataSource is changed Pin
TnTinMn6-Jun-13 9:08
TnTinMn6-Jun-13 9:08 
GeneralRe: ListBox does not update when DataSource is changed Pin
rbsbscrp6-Jun-13 12:38
rbsbscrp6-Jun-13 12:38 
GeneralRe: ListBox does not update when DataSource is changed Pin
TnTinMn6-Jun-13 13:26
TnTinMn6-Jun-13 13:26 
Perhaps I misunderstood your problem, I thought that it was that the ListBox was not automatically reflecting changes to the underlying DataSource List. The BindingList raises events that would cause the ListBox to update automatically when the List changes.

Here is a simple example. New WinForm project with two buttons and two ListBoxes. Clicking Button1 adds items to the underlying lists, but only the ListBox with the BindingList as the DataSource is update. Clicking Button2 tells ListBox1 to Refresh it's data.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        List<int> L1 = new List<int>();
        BindingList<int> L2 = new BindingList<int>();
        private void Form1_Load(object sender, EventArgs e)
        {
            L1.Add(1);
            L1.Add(2);
            L2.Add(11);
            L2.Add(22);
            listBox1.DataSource = L1;
            listBox2.DataSource = L2;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            this.button2.Click += new System.EventHandler(this.button2_Click);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            L1.Add(3);  // adds a value to L1, but listBox1 does not display it until the binding is refresshed
            L2.Add(33); // adds a value to L2 and listBox2 is automatically refreshed to display it
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // tell listBox1 to refresh the data
            ((CurrencyManager)this.BindingContext[L1]).Refresh();
        }
    }
}

AnswerRe: ListBox does not update when DataSource is changed Pin
Chirag Baroliya R24-May-13 2:25
Chirag Baroliya R24-May-13 2:25 
GeneralRe: ListBox does not update when DataSource is changed Pin
rbsbscrp24-May-13 20:11
rbsbscrp24-May-13 20:11 
QuestionBinding a DataGridView column to a nullable property, using a ComboBox bound to a non-nullable property. Pin
Brady Kelly14-May-13 21:20
Brady Kelly14-May-13 21:20 
QuestionControl hide/show(should be post here, right?) Pin
kenmaMoon23-Apr-13 21:20
kenmaMoon23-Apr-13 21:20 
AnswerRe: Control hide/show(should be post here, right?) Pin
Richard MacCutchan23-Apr-13 21:57
mveRichard MacCutchan23-Apr-13 21:57 
GeneralRe: Control hide/show(should be post here, right?) Pin
kenmaMoon23-Apr-13 22:00
kenmaMoon23-Apr-13 22:00 
GeneralRe: Control hide/show(should be post here, right?) Pin
Richard MacCutchan23-Apr-13 22:42
mveRichard MacCutchan23-Apr-13 22:42 
AnswerRe: Control hide/show(should be post here, right?) Pin
Eddy Vluggen23-Apr-13 22:50
professionalEddy Vluggen23-Apr-13 22:50 
GeneralRe: Control hide/show(should be post here, right?) Pin
kenmaMoon23-Apr-13 22:55
kenmaMoon23-Apr-13 22:55 
AnswerRe: Control hide/show(should be post here, right?) Pin
Eddy Vluggen24-Apr-13 6:29
professionalEddy Vluggen24-Apr-13 6:29 
QuestionC# Winform controls not drawing Pin
Member 783446019-Apr-13 7:01
Member 783446019-Apr-13 7:01 
AnswerRe: C# Winform controls not drawing Pin
Eddy Vluggen22-Apr-13 8:52
professionalEddy Vluggen22-Apr-13 8:52 
QuestionChanging BackColor for tabControl Pin
_katon_11-Apr-13 2:54
_katon_11-Apr-13 2:54 
AnswerRe: Changing BackColor for tabControl Pin
Alan N11-Apr-13 3:48
Alan N11-Apr-13 3:48 
GeneralRe: Changing BackColor for tabControl Pin
_katon_11-Apr-13 4:29
_katon_11-Apr-13 4:29 
AnswerRe: Changing BackColor for tabControl Pin
Dave Kreskowiak11-Apr-13 5:02
mveDave Kreskowiak11-Apr-13 5:02 
QuestionHow to link drawings on on-line maps to the map Pin
Member 843537226-Mar-13 11:40
Member 843537226-Mar-13 11:40 
AnswerRe: How to link drawings on on-line maps to the map Pin
Bernhard Hiller26-Mar-13 22:47
Bernhard Hiller26-Mar-13 22:47 
GeneralRe: How to link drawings on on-line maps to the map Pin
Member 843537227-Mar-13 0:35
Member 843537227-Mar-13 0:35 
GeneralRe: How to link drawings on on-line maps to the map Pin
Member 843537227-Mar-13 1:53
Member 843537227-Mar-13 1:53 
GeneralRe: How to link drawings on on-line maps to the map Pin
Bernhard Hiller27-Mar-13 22:18
Bernhard Hiller27-Mar-13 22:18 
QuestionNeed guidance for chat conversion UI area designing (win form c#) Pin
Tridip Bhattacharjee25-Mar-13 5:03
professionalTridip Bhattacharjee25-Mar-13 5:03 

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.