using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Windows.Forms;

namespace ListViewIcons
{
    public static class ListViewExtensions
    {
        // Make the ListView's column headers.
        // The ParamArray entries should alternate between
        // strings and HorizontalAlignment values.
        public static void MakeColumnHeaders(this ListView lvw, params object[] headerInfo)
        {
            // Remove any existing headers.
            lvw.Columns.Clear();

            // Make the column headers.
            for (int i = headerInfo.GetLowerBound(0);
                i <= headerInfo.GetUpperBound(0);
                i += 3)
            {
                lvw.Columns.Add(
                    (string)headerInfo[i],
                    (int)headerInfo[i + 1],
                    (HorizontalAlignment)headerInfo[i + 2]);
            }
        }

        // Add a row to the ListView.
        public static ListViewItem AddRow(this ListView lvw, int imageIndex,
            params string[] values)
        {
            // Make the item.
            ListViewItem newItem = new ListViewItem(values, imageIndex);
            lvw.Items.Add(newItem);
            return newItem;
        }
    }
}
