Here is the code I am using.
foreach (DataRow row in data.Rows)
{
ListViewItem lst = default(ListViewItem);
lst = lvw.Items.Add(row(0)); // My error is on row
for (int i = 1; i <= data.Columns.Count - 1; i++)
{
lst.SubItems.Add(row(i));
}
}
Now, what I'm doing or trying to do is actually add database items onto my listview
. However, I can't seem to get my rows onto my list view. I get a syntax error:
'Rows' is a 'variable' but is used like a 'method'.
I have been struggling with this winform for a couple days and my coding has stopped dead at this point. I have tried changing the parenthesis. Here is the whole function. I got it from the internet in vb.net and ran the code it worked. I then configured that code for my application in vb.net that worked too, now after converting to c# and it doesn't work which is my problem. I went through all the code(I am new to c# like relatively) and fixed most of it to work for my application except the row error
private void ShowDataInLvw(DataTable data, ListView lvw)
{
lvw.View = View.Details;
lvw.GridLines = true;
lvw.Columns.Clear();
lvw.Items.Clear();
foreach (DataColumn col in data.Columns)
{
lvw.Columns.Add(col.ToString());
}
foreach (DataRow row in data.Rows)
{
ListViewItem lst = default(ListViewItem);
lst = lvw.Items.Add(row(0));
for (int i = 1; i <= data.Columns.Count - 1; i++)
{
lst.SubItems.Add(row(i));
}
}
}