473,725 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filling a ListView from a SQLCE Datareader

I have a working version of this in VB, tryign to translate everything over
to C#.
In the C# version this is filling the listview, the first couple columns are
ok, but the last few are going screwy.
In VB, it is working perfectly.

The reason for move is speed. Takes a full 10 - 15 seconds to run this on
VB, <5 in C#.

I adapted this from
http://www.codeguru.com/vb/controls/...icle.php/c3979
to allow for non-string fields to be used.

My VB:
#Region "Listview Data Adapter Use: classvariable.F illListView(Lis tView,
SQLCEDataSource )"
Public Sub FillListView(By Ref MyListView As ListView, ByRef myData As
SqlCeDataReader )
Dim lvwColumn As ColumnHeader
Dim itmListItem As ListViewItem
Dim strTest As String
Dim strTemp As String
Dim shtCntr As Short
MyListView.Clea r()
For shtCntr = 0 To myData.FieldCou nt() - 1
lvwColumn = New ColumnHeader
lvwColumn.Text = myData.GetName( shtCntr)
MyListView.Colu mns.Add(lvwColu mn)
Next
While myData.Read
itmListItem = New ListViewItem
strTest = IIf(myData.IsDB Null(0), "", myData.Item(0))
itmListItem.Tex t = strTest
For shtCntr = 1 To myData.FieldCou nt() - 1
If myData.IsDBNull (shtCntr) Then
itmListItem.Sub Items.Add("")
Else
strTemp = myData.Item(sht Cntr)
itmListItem.Sub Items.Add(strTe mp)
End If
Next shtCntr
MyListView.Item s.Add(itmListIt em)
End While
End Sub
My C#:

#region "Listview Data Adapter Use: classvariable.F illListView(Lis tView,
SQLCEDataSource )"
public void FillListView(Li stView m_ListView, SqlCeDataReader myData)
{
ColumnHeader lvwColumn = new ColumnHeader();
m_ListView.Clea r();
for (int acounter = 0; acounter <= (myData.FieldCo unt - 1);
acounter++)
{
lvwColumn = new ColumnHeader();
lvwColumn.Text = myData.GetName( acounter);
m_ListView.Colu mns.Add(lvwColu mn);
} // End: for (int acounter = 0; acounter <=
(myData.FieldCo unt - 1); acounter++)
while (myData.Read())
{
string strTest;
if (myData.IsDBNul l(0))
strTest = "";
else
strTest = myData.GetStrin g(0);
ListViewItem itmListItem = new ListViewItem(st rTest);
for (int bcounter = 1; bcounter <= (myData.FieldCo unt - 1);
bcounter++)
{
string strTemp = "";
if (myData.IsDBNul l(bcounter))
itmListItem.Sub Items.Add("");
else
strTemp =
Convert.ToStrin g(myData.GetVal ue(bcounter));
itmListItem.Sub Items.Add(strTe mp);
} // End: for (int bcounter = 1; bcounter <=
(myData.FieldCo unt - 1); bcounter++)
m_ListView.Item s.Add(itmListIt em);
}// End: while (myData.Read())
}// End: public void FillListView
#endregion
Nov 16 '05 #1
0 4480

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

Similar topics

0
1362
by: Mike Barrett | last post by:
I have a strange one here and I believe it is a bug. I googled it and saw others having a similar issue and nobody seems to have a fix. I will take another shot. I get this ERROR MESSAGE... "Specified argument was out of the range of valid values. Parameter Name: '9' is not a valid value for 'index'." ....when I attempt to "Refresh" a ListView control AFTER it has been sorted.
6
4655
by: VM | last post by:
How can I fill up a listview with text file contents? My listview has two columns and the first column fills up with a while loop: while (myString != null) { myString = sr.Readline(); listView1.Items.Add (myString); } Is there a way I can fill up the second column this easily? Thw way I'm currently doing it is using the subitems property to add it. Unfortunately,
1
1669
by: utkuozan | last post by:
I want to fill an existing ListView with colors and color codes. All color codes are held in an ArrayList as RGB. I have two columns in ListView. I want to fill the ListView with items as the color index as text and having a small thumbnail of the color as Image. Filling the text is quite easy. ( ColorIndexArray .ToString ( ) ) But how can I add the color, for example {123,23,41} as the image in front of the text? Is it possible to...
6
9049
by: Brian Henry | last post by:
I was wondering how you guys would handle filling a list view with something like 10,000 items which each have 10 sub items on them... there has to be major speed issues with that right? Yet, applications like outlook and such can retrieve and display tens of thousands of emails with virtually no performance hit at all... how would we go about getting a .NET listview to get similar performance? when I try to do what I said above, it takes...
7
15002
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The MyList data is resident in a dataset table. I'm stuck and can't choose either because. If I choose ListView as my control I don't understand how to programmatically get the data from the dataset table
0
1350
by: Jason Huang | last post by:
Hi, In my C# Windows Form MyForm, it has a ListView ListView1. How do I fill the data from a DataReader into ListView1 if the DataReader if the DataReader has 3 rows and 5 columns? Thanks for help. Jason
5
4747
by: Titeuf | last post by:
ok I start programming mobile application with VB.NET (VS 2005) I am interested work with Sqlce Also I look for add reference in my project I search "System.Data.SqlServerCe" but not found. Where is? Sqlce is not installed by default? Thanks
3
5408
by: Martin Panggabean | last post by:
Hello All, I've kind a logic problem ... I want to fill the listView control in VB.NET with data in my mySql table using Datareader object component. But It seems that the way of how listView being used is quite different from usual column-row component like Grid component. If you kind a familiar using listView, u must have known what i'm talking about. Here is some example i took from MSDN :...
0
1082
by: dariosalvi78 | last post by:
Hi, I am trying to use MyGeneration with a SQLCe database in the Compact Framework 2 environment. My first problem now is that MyGeneration (its latest version) has no template for the SqlCe as far as I know. The SQL Server template seems easily adaptable to the sqlce, but before starting generating a new template I would like to ask you if there is a SQLCe specific template somewhere.
0
8889
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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
9257
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
9179
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,...
1
6702
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
6011
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
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2637
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.