473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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.FillListView(ListView,
SQLCEDataSource)"
Public Sub FillListView(ByRef 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.Clear()
For shtCntr = 0 To myData.FieldCount() - 1
lvwColumn = New ColumnHeader
lvwColumn.Text = myData.GetName(shtCntr)
MyListView.Columns.Add(lvwColumn)
Next
While myData.Read
itmListItem = New ListViewItem
strTest = IIf(myData.IsDBNull(0), "", myData.Item(0))
itmListItem.Text = strTest
For shtCntr = 1 To myData.FieldCount() - 1
If myData.IsDBNull(shtCntr) Then
itmListItem.SubItems.Add("")
Else
strTemp = myData.Item(shtCntr)
itmListItem.SubItems.Add(strTemp)
End If
Next shtCntr
MyListView.Items.Add(itmListItem)
End While
End Sub
My C#:

#region "Listview Data Adapter Use: classvariable.FillListView(ListView,
SQLCEDataSource)"
public void FillListView(ListView m_ListView, SqlCeDataReader myData)
{
ColumnHeader lvwColumn = new ColumnHeader();
m_ListView.Clear();
for (int acounter = 0; acounter <= (myData.FieldCount - 1);
acounter++)
{
lvwColumn = new ColumnHeader();
lvwColumn.Text = myData.GetName(acounter);
m_ListView.Columns.Add(lvwColumn);
} // End: for (int acounter = 0; acounter <=
(myData.FieldCount - 1); acounter++)
while (myData.Read())
{
string strTest;
if (myData.IsDBNull(0))
strTest = "";
else
strTest = myData.GetString(0);
ListViewItem itmListItem = new ListViewItem(strTest);
for (int bcounter = 1; bcounter <= (myData.FieldCount - 1);
bcounter++)
{
string strTemp = "";
if (myData.IsDBNull(bcounter))
itmListItem.SubItems.Add("");
else
strTemp =
Convert.ToString(myData.GetValue(bcounter));
itmListItem.SubItems.Add(strTemp);
} // End: for (int bcounter = 1; bcounter <=
(myData.FieldCount - 1); bcounter++)
m_ListView.Items.Add(itmListItem);
}// End: while (myData.Read())
}// End: public void FillListView
#endregion
Nov 16 '05 #1
0 4447

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

Similar topics

0
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... ...
6
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();...
1
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...
6
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,...
7
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...
0
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...
5
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....
3
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...
0
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.