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