[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
/// Copies the columns.
/// <param name="indices">The indices.</param>
/// <param name="listSrc">The list SRC.</param>
/// <param name="listDest">The list dest.</param>
private void CopyColumns(int indices, ListView listSrc, ListView listDest)
foreach (int colindex in indices)
ColumnHeader ch = listSrc.Columns[colindex];
//clone the column from listview1 and add to listview2
listDest.Columns.Add(ch.Clone() as ColumnHeader);
//iterate items to fill data in new columns
foreach (ListViewItem item in listSrc.Items)
string val = item.SubItems[colindex].Text;
//listview1 has more items than listview2 we need first to add new item
//and also add subitem for the new column
if (listDest.Items.Count < item.Index + 1)
listDest.Items.Add(new ListViewItem(listDest.Columns.Cast<ColumnHeader>().Select(n => string.Empty).ToArray()));
listDest.Items[item.Index].SubItems[listDest.Columns.Count - 1].Text = val;
else//just add the subitem for the new column
Open in new window
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.