private void LoadColumns()
        {
            SPColumn selCol = lstColumns.SelectedItem as SPColumn;

            lstColumns.Items.Clear();
            if (_list != null)
            {
                SortedList <string, SPColumn> sortedCols = new SortedList <string, SPColumn>();
                foreach (SPColumn curCol in _list.GetColumns(true))
                {
                    if (!curCol.includeInCode)
                    {
                        if (!curCol.Hidden || _settings.ShowHiddenColumns)
                        {
                            sortedCols.Add(curCol.ToString(), curCol);
                        }
                    }
                }
                lstColumns.Items.AddRange(sortedCols.Values.ToArray());
                if (selCol != null && lstColumns.Items.Contains(selCol))
                {
                    lstColumns.SelectedItem = selCol;
                }
            }
            btnOK.Enabled = lstColumns.SelectedItem != null;
        }
        private void PopulateColumns(bool refresh)
        {
            Cursor backup = Cursor.Current;

            lvColumns.Items.Clear();
            SPList selList = lstLists.SelectedItem as SPList;

            if (selList != null)
            {
                try
                {
                    lvColumns.Columns.Clear();
                    if (settings.ShowHiddenColumns)
                    {
                        this.lvColumns.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
                            this.columnHeader1,
                            this.columnHeader3,
                            this.colHeaderHidden,
                            this.columnHeader2
                        });
                    }
                    else
                    {
                        this.lvColumns.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
                            this.columnHeader1,
                            this.columnHeader3,
                            this.columnHeader2
                        });
                    }
                    tsLabel.Text = string.Format("Retrieving Field Information for {0}", selList.Title);
                    Application.DoEvents();
                    Cursor.Current = Cursors.WaitCursor;
                    List <SPColumn> fields = selList.GetColumns(refresh);
                    if (refresh && originalColumns != null && originalColumns.Count > 0)
                    {
                        foreach (SPColumn col in fields)
                        {
                            if (originalColumns.Contains(col))
                            {
                                int      ndx  = originalColumns.IndexOf(col);
                                SPColumn orig = originalColumns[ndx];
                                col.includeInCode = orig.includeInCode;
                                col.SASOrder      = orig.SASOrder;
                                originalColumns.RemoveAt(ndx);
                            }
                            if (originalColumns.Count == 0)
                            {
                                originalColumns = null;
                                break;
                            }
                        }
                    }
                    foreach (SPColumn col in fields)
                    {
                        if (chkHiddenCols.Checked || !col.Hidden)
                        {
                            ListViewItem lvi = new ListViewItem();
                            lvi.Text = col.Title;
                            string[] subranges = null;
                            if (settings.ShowHiddenColumns)
                            {
                                subranges = new string[] { col.SPFieldType, col.Hidden.ToString(), col.Description }
                            }
                            ;
                            else
                            {
                                subranges = new string[] { col.SPFieldType, col.Description }
                            };

                            lvi.SubItems.AddRange(subranges);
                            lvi.Tag      = col;
                            lvi.Selected = col.includeInCode;
                            lvColumns.Items.Add(lvi);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ImportFromSharePointListTaskForm.DisplayError("Error getting list information", ex);
                }
                finally
                {
                    Cursor.Current = backup;
                    tsLabel.Text   = "Ready";
                    _bNeedRefresh  = false;
                }
            }
        }