private void LoadList()
{
// Get the table from the data set
DataTable dtable = _DataSet.Tables["Titles"];
// Clear the ListView control
listView1.Items.Clear();
// Display items in the ListView control
for (int i = 0; i < dtable.Rows.Count; i++)
{
DataRow drow = dtable.Rows[i];
// Only row that have not been deleted
if (drow.RowState != DataRowState.Deleted)
{
// Define the list items
ListViewItem lvi = new ListViewItem(drow["title"].ToString());
lvi.SubItems.Add (drow["title_id"].ToString());
lvi.SubItems.Add (drow["price"].ToString());
lvi.SubItems.Add (drow["pubdate"].ToString());
// Add the list items to the ListView
listView1.Items.Add(lvi);
}
}
}
でもなどを仕分け検索 - 修正http://www.akadia.com/services/dotnet_listview_sort_dataset.html
-
// Clear the ListView control
listView1.Items.Clear();
int ColCount = dtable.Columns.Count;
//Add columns
for (int k = 0; k < ColCount; k++)
{
listView1.Columns.Add(dtable.Columns[k].ColumnName);
}
// Display items in the ListView control
for (int i = 0; i < dtable.Rows.Count; i++)
{
DataRow drow = dtable.Rows[i];
// Only row that have not been deleted
if (drow.RowState != DataRowState.Deleted)
{
// Define the list items
ListViewItem lvi = new ListViewItem(drow[0].ToString());
for (int j = 1; j < ColCount; j++)
{
lvi.SubItems.Add(drow[j].ToString());
}
// Add the list items to the ListView
listView1.Items.Add(lvi);
}
}
DataTableを指定すると、Columnsプロパティの列とその名前が完全によくわかります。 ListViewをそのように配置するのはなぜ難しいと思いますか? –
なぜ 'DataGridView'を使わないのですか? – leppie