internal void SetItemText(int itemIndex, int subItemIndex, string text)
 {
     System.Windows.Forms.NativeMethods.LVITEM lvItem = new System.Windows.Forms.NativeMethods.LVITEM();
     this.SetItemText(itemIndex, subItemIndex, text, ref lvItem);
 }
 private int DisplayIndexToID(int displayIndex)
 {
     if (this.owner.IsHandleCreated && !this.owner.ListViewHandleDestroyed)
     {
         System.Windows.Forms.NativeMethods.LVITEM lParam = new System.Windows.Forms.NativeMethods.LVITEM {
             mask = 4,
             iItem = displayIndex
         };
         System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this.owner, this.owner.Handle), System.Windows.Forms.NativeMethods.LVM_GETITEM, 0, ref lParam);
         return (int) lParam.lParam;
     }
     return this[displayIndex].ID;
 }
 internal void SetItemState(int index, int state, int mask)
 {
     if (((index < -1) || (this.VirtualMode && (index >= this.VirtualListSize))) || (!this.VirtualMode && (index >= this.itemCount)))
     {
         throw new ArgumentOutOfRangeException("index", System.Windows.Forms.SR.GetString("InvalidArgument", new object[] { "index", index.ToString(CultureInfo.CurrentCulture) }));
     }
     if (base.IsHandleCreated)
     {
         System.Windows.Forms.NativeMethods.LVITEM lParam = new System.Windows.Forms.NativeMethods.LVITEM {
             mask = 8,
             state = state,
             stateMask = mask
         };
         System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x102b, index, ref lParam);
     }
 }
 private void RealizeAllSubItems()
 {
     System.Windows.Forms.NativeMethods.LVITEM lvItem = new System.Windows.Forms.NativeMethods.LVITEM();
     for (int i = 0; i < this.itemCount; i++)
     {
         int count = this.Items[i].SubItems.Count;
         for (int j = 0; j < count; j++)
         {
             this.SetItemText(i, j, this.Items[i].SubItems[j].Text, ref lvItem);
         }
     }
 }
 private int InsertItemsNative(int index, ListViewItem[] items)
 {
     if ((items == null) || (items.Length == 0))
     {
         return 0;
     }
     if (index == (this.itemCount - 1))
     {
         index++;
     }
     System.Windows.Forms.NativeMethods.LVITEM lvItem = new System.Windows.Forms.NativeMethods.LVITEM();
     int num = -1;
     IntPtr zero = IntPtr.Zero;
     int cColumns = 0;
     this.listViewState1[1] = true;
     try
     {
         base.SendMessage(0x102f, this.itemCount, 0);
         for (int i = 0; i < items.Length; i++)
         {
             int num5;
             ListViewItem item = items[i];
             lvItem.Reset();
             lvItem.mask = 0x17;
             lvItem.iItem = index + i;
             lvItem.pszText = item.Text;
             lvItem.iImage = item.ImageIndexer.ActualIndex;
             lvItem.iIndent = item.IndentCount;
             lvItem.lParam = (IntPtr) item.ID;
             if (this.GroupsEnabled)
             {
                 lvItem.mask |= 0x100;
                 lvItem.iGroupId = this.GetNativeGroupId(item);
             }
             lvItem.mask |= 0x200;
             lvItem.cColumns = (this.columnHeaders != null) ? Math.Min(20, this.columnHeaders.Length) : 0;
             if ((lvItem.cColumns > cColumns) || (zero == IntPtr.Zero))
             {
                 if (zero != IntPtr.Zero)
                 {
                     Marshal.FreeHGlobal(zero);
                 }
                 zero = Marshal.AllocHGlobal((int) (lvItem.cColumns * Marshal.SizeOf(typeof(int))));
                 cColumns = lvItem.cColumns;
             }
             lvItem.puColumns = zero;
             int[] source = new int[lvItem.cColumns];
             for (int j = 0; j < lvItem.cColumns; j++)
             {
                 source[j] = j + 1;
             }
             Marshal.Copy(source, 0, lvItem.puColumns, lvItem.cColumns);
             ItemCheckEventHandler onItemCheck = this.onItemCheck;
             this.onItemCheck = null;
             try
             {
                 item.UpdateStateToListView(lvItem.iItem, ref lvItem, false);
                 num5 = (int) System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), System.Windows.Forms.NativeMethods.LVM_INSERTITEM, 0, ref lvItem);
                 if (num == -1)
                 {
                     num = num5;
                     index = num;
                 }
             }
             finally
             {
                 this.onItemCheck = onItemCheck;
             }
             if (-1 == num5)
             {
                 throw new InvalidOperationException(System.Windows.Forms.SR.GetString("ListViewAddItemFailed"));
             }
             for (int k = 1; k < item.SubItems.Count; k++)
             {
                 this.SetItemText(num5, k, item.SubItems[k].Text, ref lvItem);
             }
             if (item.StateImageSet || item.StateSelected)
             {
                 this.SetItemState(num5, lvItem.state, lvItem.stateMask);
             }
         }
     }
     finally
     {
         if (zero != IntPtr.Zero)
         {
             Marshal.FreeHGlobal(zero);
         }
         this.listViewState1[1] = false;
     }
     if (this.listViewState1[0x10])
     {
         this.listViewState1[0x10] = false;
         this.OnSelectedIndexChanged(EventArgs.Empty);
     }
     if (this.FlipViewToLargeIconAndSmallIcon)
     {
         this.FlipViewToLargeIconAndSmallIcon = false;
         this.View = System.Windows.Forms.View.LargeIcon;
         this.View = System.Windows.Forms.View.SmallIcon;
     }
     return num;
 }
 internal void UpdateStateToListView(int index)
 {
     System.Windows.Forms.NativeMethods.LVITEM lvItem = new System.Windows.Forms.NativeMethods.LVITEM();
     this.UpdateStateToListView(index, ref lvItem, true);
 }
 internal void UpdateStateFromListView(int displayIndex, bool checkSelection)
 {
     if (((this.listView != null) && this.listView.IsHandleCreated) && (displayIndex != -1))
     {
         System.Windows.Forms.NativeMethods.LVITEM lParam = new System.Windows.Forms.NativeMethods.LVITEM {
             mask = 0x10c
         };
         if (checkSelection)
         {
             lParam.stateMask = 2;
         }
         lParam.stateMask |= 0xf000;
         if (lParam.stateMask != 0)
         {
             lParam.iItem = displayIndex;
             System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this.listView, this.listView.Handle), System.Windows.Forms.NativeMethods.LVM_GETITEM, 0, ref lParam);
             if (checkSelection)
             {
                 this.StateSelected = (lParam.state & 2) != 0;
             }
             this.SavedStateImageIndex = ((lParam.state & 0xf000) >> 12) - 1;
             this.group = null;
             foreach (ListViewGroup group in this.ListView.Groups)
             {
                 if (group.ID == lParam.iGroupId)
                 {
                     this.group = group;
                     break;
                 }
             }
         }
     }
 }