Click here to Skip to main content
15,922,015 members
Home / Discussions / C#
   

C#

 
GeneralRe: Adding items to ListView Pin
Tarakeshwar Reddy5-Jun-07 3:43
professionalTarakeshwar Reddy5-Jun-07 3:43 
GeneralRe: Adding items to ListView Pin
Rajesh R Subramanian5-Jun-07 3:46
professionalRajesh R Subramanian5-Jun-07 3:46 
GeneralRe: Adding items to ListView Pin
Sathesh Sakthivel5-Jun-07 3:37
Sathesh Sakthivel5-Jun-07 3:37 
GeneralRe: Adding items to ListView Pin
Rajesh R Subramanian5-Jun-07 3:40
professionalRajesh R Subramanian5-Jun-07 3:40 
GeneralRe: Adding items to ListView Pin
Sathesh Sakthivel5-Jun-07 3:42
Sathesh Sakthivel5-Jun-07 3:42 
AnswerRe: Adding items to ListView Pin
S. Senthil Kumar5-Jun-07 4:33
S. Senthil Kumar5-Jun-07 4:33 
GeneralRe: Adding items to ListView Pin
Rajesh R Subramanian5-Jun-07 19:49
professionalRajesh R Subramanian5-Jun-07 19:49 
GeneralRe: Adding items to ListView Pin
S. Senthil Kumar6-Jun-07 4:40
S. Senthil Kumar6-Jun-07 4:40 
brahmma wrote:
Actually, I am retrieving data from a database and populating a ListView object with it. The UI operation seems to be slow and so I thought I would do it in the memory


What exactly is the bottleneck, retrieiving data from the database or adding elements to the listview? If it's the former, you can use a separate thread to retrieve data and construct a list of ListViewItem and then use the UI thread to add the ListViewItems to the ListView. Something like
ListView listView;

delegate void UpdateListViewDelegate(List<ListViewItem> listViewItems);
void DBDataLoaderThread()
{
  List<ListViewItem> items = new List<ListViewItem>();
  ...
  while (dataReader.Read())
  {
     items.Add(new ListViewItem(...));
  }
  listView.BeginInvoke(new UpdateListViewDelegate(UpdateListView), new object[] { items } );
}

void UpdateListView(List<ListViewItems> listViewItems)
{
   foreach(ListViewItem item in listViewItems)
   {
      listView.Items.Add(item);
   }
}


If it's the latter, you can use BeginUpdate</code. before starting to add elements to the <code>ListView and EndUpdate after it - this will prevent the ListView from repainting after adding each element.
void UpdateListView(List<ListViewItems> listViewItems)
{
   listView.BeginUpdate();
   foreach(ListViewItem item in listViewItems)
   {
      listView.Items.Add(item);
   }
   listView.EndUpdate();
}




Regards
Senthil [MVP - Visual C#]
_____________________________
My Blog | My Articles | My Flickr | WinMacro

GeneralRe: Adding items to ListView Pin
Rajesh R Subramanian6-Jun-07 18:45
professionalRajesh R Subramanian6-Jun-07 18:45 
QuestionAdding button to datagridview Pin
sulabh20205-Jun-07 2:47
sulabh20205-Jun-07 2:47 
AnswerRe: Adding button to datagridview Pin
Seishin#5-Jun-07 4:11
Seishin#5-Jun-07 4:11 
AnswerRe: Adding button to datagridview Pin
Hesham Yassin6-Jun-07 8:14
Hesham Yassin6-Jun-07 8:14 
QuestionReporting Service MultiLanguage? Pin
ArunkumarSundaravelu5-Jun-07 2:04
ArunkumarSundaravelu5-Jun-07 2:04 
QuestionInternet Explorer Toolbar, tutorial anywere? Pin
Jens R. Nielsen5-Jun-07 1:39
Jens R. Nielsen5-Jun-07 1:39 
AnswerRe: Internet Explorer Toolbar, tutorial anywere? Pin
Jens R. Nielsen6-Jun-07 6:26
Jens R. Nielsen6-Jun-07 6:26 
QuestionExcel worksheet Pin
Ankit Aneja5-Jun-07 1:39
Ankit Aneja5-Jun-07 1:39 
QuestionHow to reopen program automatically Pin
GreenblitZ5-Jun-07 1:36
GreenblitZ5-Jun-07 1:36 
AnswerRe: How to reopen program automatically Pin
CPallini5-Jun-07 1:55
mveCPallini5-Jun-07 1:55 
GeneralRe: How to reopen program automatically Pin
GreenblitZ5-Jun-07 2:30
GreenblitZ5-Jun-07 2:30 
GeneralRe: How to reopen program automatically Pin
Vikram A Punathambekar5-Jun-07 4:06
Vikram A Punathambekar5-Jun-07 4:06 
AnswerRe: How to reopen program automatically Pin
Seishin#5-Jun-07 4:16
Seishin#5-Jun-07 4:16 
QuestionScheduled command line application Pin
weywe47k375-Jun-07 1:32
weywe47k375-Jun-07 1:32 
AnswerRe: Scheduled command line application Pin
CPallini5-Jun-07 2:02
mveCPallini5-Jun-07 2:02 
AnswerRe: Scheduled command line application Pin
thowra5-Jun-07 4:32
thowra5-Jun-07 4:32 
AnswerRe: Scheduled command line application Pin
Joseph Guadagno5-Jun-07 4:35
Joseph Guadagno5-Jun-07 4:35 

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.