Click here to Skip to main content
15,891,777 members
Home / Discussions / C#
   

C#

 
GeneralRe: Cross Threads problemo (invalidoperationexception) Pin
Quake2Player22-Jun-09 8:36
Quake2Player22-Jun-09 8:36 
Question_ID field goes wrong Pin
misCafe22-May-09 15:28
misCafe22-May-09 15:28 
AnswerRe: _ID field goes wrong Pin
Luc Pattyn22-May-09 16:13
sitebuilderLuc Pattyn22-May-09 16:13 
GeneralRe: _ID field goes wrong Pin
misCafe22-May-09 16:43
misCafe22-May-09 16:43 
GeneralRe: _ID field goes wrong Pin
fly90422-May-09 17:10
fly90422-May-09 17:10 
GeneralRe: _ID field goes wrong Pin
Luc Pattyn22-May-09 17:18
sitebuilderLuc Pattyn22-May-09 17:18 
GeneralRe: _ID field goes wrong Pin
Luc Pattyn22-May-09 17:19
sitebuilderLuc Pattyn22-May-09 17:19 
AnswerRe: _ID field goes wrong Pin
fly90422-May-09 16:34
fly90422-May-09 16:34 
misCafe wrote:
while (sReader.Read() == true)
{
_ID.Add(sReader[0].ToString());

for (int i = 0; i < _ID.Count; i++)
//for (int i = 0; i < sReader.FieldCount; i++ )
{
lstItems = new ListViewItem((i + 1).ToString());
lstItems.SubItems.Add(sReader[1].ToString());
lstItems.SubItems.Add(sReader[2].ToString());
lstItems.SubItems.Add(sReader[3].ToString());
lstItems.SubItems.Add(sReader[4].ToString());
lstItems.SubItems.Add(sReader[5].ToString());
this.lsv_user.Items.Add(lstItems);
}
}


With that, you are adding the same record to the ListView n(sReader.FieldCount) times. Your problem is the line in bold, you are adding the same ID/name ((i + 1).ToString()) for each record. Each ListViewItem should have a different name or be blank (no parameter).

I think I know what you are trying to do, so I hope this helps:

if (sReader.FieldCount > 0)
{
    _ID.Add(sReader[0].ToString());
    lstItems = new ListViewItem(sReader[0].ToString()); //Notice: If this is your ID column then it should be unique each record.
    for (int i = 1; i < sReader.FieldCount; i++)
    {
        lstItems.SubItems.Add(sReader[i].ToString());
    }
    this.lsv_user.Items.Add(lstItems);
}
You just need to replace the content of your while loop.

My failometer is detecting vast quantities of FAIL!

"Its SQL - hardly programming..." (Caslen)

GeneralRe: _ID field goes wrong Pin
misCafe22-May-09 17:27
misCafe22-May-09 17:27 
Questionwindows installer user interface checkbox to disable next button Pin
Member 202095122-May-09 11:07
Member 202095122-May-09 11:07 
QuestionChange FileAccess/FileShare permissions on a FileStream Pin
Dan Neely22-May-09 10:18
Dan Neely22-May-09 10:18 
AnswerRe: Change FileAccess/FileShare permissions on a FileStream Pin
Luc Pattyn22-May-09 11:21
sitebuilderLuc Pattyn22-May-09 11:21 
GeneralRe: Change FileAccess/FileShare permissions on a FileStream Pin
Dan Neely22-May-09 15:52
Dan Neely22-May-09 15:52 
QuestionHow to get the roles for a user other than the current one Pin
MGoetz22-May-09 8:22
MGoetz22-May-09 8:22 
AnswerRe: How to get the roles for a user other than the current one Pin
0x3c022-May-09 8:48
0x3c022-May-09 8:48 
GeneralRe: How to get the roles for a user other than the current one Pin
MGoetz22-May-09 9:13
MGoetz22-May-09 9:13 
GeneralRe: How to get the roles for a user other than the current one Pin
MGoetz26-May-09 4:44
MGoetz26-May-09 4:44 
Questionexternal database? Pin
benjamin yap22-May-09 6:55
benjamin yap22-May-09 6:55 
AnswerRe: external database? Pin
EliottA22-May-09 7:06
EliottA22-May-09 7:06 
GeneralRe: external database? Pin
benjamin yap22-May-09 7:09
benjamin yap22-May-09 7:09 
GeneralRe: external database? Pin
EliottA22-May-09 7:14
EliottA22-May-09 7:14 
GeneralRe: external database? Pin
benjamin yap22-May-09 7:21
benjamin yap22-May-09 7:21 
GeneralRe: external database? Pin
EliottA22-May-09 7:27
EliottA22-May-09 7:27 
GeneralRe: external database? Pin
ameeen22-May-09 8:52
ameeen22-May-09 8:52 
GeneralRe: external database? Pin
EliottA22-May-09 9:36
EliottA22-May-09 9:36 

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.