473,804 Members | 3,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListBox Populating Question

I populate a ListBox with a LogFile that has about (~1000 lines). The
ListBox's datasource is a BindingList<str ing>. Whenever I add the
elements, with the datasource set, it takes about 2 mins.

I've tried wrapping "Listbox.Suspen dLayout()" and
"Listbox.Resume Layout()" around the for loop (that does the adding)
but it still takes about 2 mins. Only thing I can seem to do is set
the DataSource to null, add to the BindingList and then reset the
DataSource (this way the ListBox is populated in about 1 second or
less)... Which, I think, defeats the purpose of the BindingList?

How do I tell the ListBox (or the BindingList) to temporarly stop
updating its bindings? Then I can just call the ".ResetBindings ()"
function after I'm done adding to the BindingList.

Thanks
NB
Jan 15 '08 #1
2 3831
Well, if you still a BindingSource between the ListBox and the
BindingList<T>, then you can simply suspend the BindingSource:

bindingSource1. DataSource = list;
listbox1.DataSo urce = bindingSource1;
// ...
bindingSource1. SuspendBinding( );
// ...
bindingSource1. ResumeBinding() ;
// (might also need bindingSource1. ResetBindings(f alse);
// but see how it goes without first)

Alternatively, you can just tell the list itself to shut up for a
while:

bool wasEnabled = list.RaiseListC hangedEvents;
list.RaiseListC hangedEvents = false;
try
{
// ...
}
finally
{
if (wasEnabled) // then re-enable it and force a
refresh
{
list.RaiseListC hangedEvents = true;
list.ResetBindi ngs();
}
}

That do?

Marc
Jan 16 '08 #2
On Jan 15, 11:49*pm, Marc Gravell <marc.grav...@g mail.comwrote:
Well, if you still a BindingSource between the ListBox and the
BindingList<T>, then you can simply suspend the BindingSource:

* * * * * * bindingSource1. DataSource = list;
* * * * * * listbox1.DataSo urce = bindingSource1;
* * * * * * // ...
* * * * * * bindingSource1. SuspendBinding( );
* * * * * * // ...
* * * * * * bindingSource1. ResumeBinding() ;
* * * * * * // (might also need bindingSource1. ResetBindings(f alse);
* * * * * * // but see how it goes without first)

Alternatively, you can just tell the list itself to shut up for a
while:

* * * * * * bool wasEnabled = list.RaiseListC hangedEvents;
* * * * * * list.RaiseListC hangedEvents = false;
* * * * * * try
* * * * * * {
* * * * * * * * // ...
* * * * * * }
* * * * * * finally
* * * * * * {
* * * * * * * * if (wasEnabled) // then re-enable it and force a
refresh
* * * * * * * * {
* * * * * * * * * * list.RaiseListC hangedEvents = true;
* * * * * * * * * * list.ResetBindi ngs();
* * * * * * * * }
* * * * * * }

That do?

Marc
Ahh, Thank you kindly. Both methods you mentioned works perfectly :)

NB
Jan 16 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2189
by: chambersdon | last post by:
I have created a Web Custom Control that inherits from WebControls.ListBox but can't get it to retain the selectedIndex after a postback. As a test I created a very simple version of the control with no additional code. I just inherited from the exisiting ListBox class and put the control on a page. I put this control a blank page along with a button to perform a post back. I select an item in the list box and then click the button...
2
1653
by: Mike P | last post by:
I have the following code in my Page_Load event to populate a listbox from a database : if (!(Page.IsPostBack)) { SqlConnection objConnection = new SqlConnection(ConfigurationSettings.AppSettings ); string strTelcoNumber = "SELECT DISTINCT OSValue FROM CallTypeSwitch ORDER BY OSValue";
3
1316
by: Paul W | last post by:
I am populating listbox with a datreader. DateReader sqlcommand is dynamic, based on several user selections Listbox DataValueField is set to the tables primary key Listbox DataTextField is multiple fields concatentated from SQL statement For example SELECT + ' ' + AS showText... Listbox would show the following Joe Smith... Mary Smith ... John Doe....
6
2884
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access the listbox object as an object to set the listitem's selected property before it gets rendered).. ...
4
5379
by: Henrik Holle | last post by:
Hi, i have a serverside listbox but i modify the value with javascript on the clientside. On postback my changed/added values are all lost? what am i doing wrong? Is it not possible to change the listbox content on the clientside? regards henrik
6
5228
by: Janaka | last post by:
Help! I have two ListBox controls on my web form. The first one gets populated on entry with values from the DB. I then use JavaScript to copy options from this ListBox to my second one. (I have also tried changing the second ListBox to an HtmlSelect control) using bog standard JavaScript code like so where "used" is the name of my <select> control: used.options = new Option(name, typeId); This all works fine and I can move across...
3
1483
by: joe | last post by:
I actually have 2 questions: 1) Is databinding the fastest way to load a listbox from sqlserver? speed is crucial and I want to make sure i'm populating it the fastest way i can 2) Also, i'm having trouble getting the selected items in the listbox. Will simply using the Items property (with the index) not give me
10
2651
by: Ben | last post by:
Hi Im trying to get the value from a listbox, i have the below code to get the text: txtEntity.Text = ListBox1.Text But do not seem to be able to retrieve the data that i set as the value member. Thanks
6
2344
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am populating a listbox with an array of very simple "Country" objects via a WebService. The Country class contains CountryID,TLDs and Name properties each of which have a getter and setter (I found that properties without
0
10558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9130
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.