Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with load data from datatable to listview control

Status
Not open for further replies.

jbsys

Programmer
May 6, 2005
51
CA
Hi;
I am having an issue with loading a list view control with data from a datatable. What happens is that some rows will appear as normal, and other will not. For example, the first row will appear as expected having all of the cells filled with data. The second row or third row will not but the last row will contain data as expected. Which row display data and which rows don't is not consistant from one run to the next. I don't understand what would cause this to happen. Is there some property that controls this? See Listview load code snippet below:

this.listViewColumns.Items.Clear();
this.listViewColumns.Show();
this.listViewColumns.Visible = true;
int intItems=0;
foreach(DataRow row in _dtReturned.Rows)
{
//Loads the Import Column and Level columns.
this.listViewColumns.Items.Add(row[0].ToString().Trim()).SubItems.Add(_TableName.ToString().Trim());

//Loads Star Column column.
this.listViewColumns.Items[intItems].SubItems.Add(row [0].ToString().ToLower().Trim());


//Load Import_Type/Size/Dec column;
string _impSzDec = row[1].ToString() + "/" + row[2].ToString() + "/" + row[4].ToString();
this.listViewColumns.Items[intItems].SubItems.Add(_impSzDec.ToString());

//Load Star Data Type Column.
this.listViewColumns.Items[intItems].SubItems.Add(row[5].ToString());
//Load Star Size column.
string _cstSz = row[2].ToString();
this.listViewColumns.Items[intItems].SubItems.Add(_cstSz.ToString());
//Load Star Decimals column.
string _cstDec = row[4].ToString();
this.listViewColumns.Items[intItems].SubItems.Add(_cstDec.ToString());
this.listViewColumns.Enabled = true;
}

Thanks
jbsys
 
Recommendation: Do each row at a time using ListViewItem()

Example:
ListViewItem tempItem = this.listViewColumns.Add("Your Text");
tempItem.SubItems.Add("First Sub Item");
tempItem.SubItems.Add("Second Sub Item");
.
.
.

and do that for each new row in the ListView.
 
JurkMonkey;
Thanks very much for your submission. I actually found the problem. The issues was that the Sort Property of the ListView object was set to "Ascending". As soon as I set it to "None" all of the information was displayed. I think this may have had something to do with the fact that the incoming datatable was not sorted in ascending order.

Thanks Again - much appreciated.

jbsys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top