private void updateListViewItems(ListView listView, flashHeaderStruct block) { if (listView.InvokeRequired) { updateListViewCallback d = new updateListViewCallback(updateListViewItems); this.Invoke(d, new object[] { listView, block }); } else { ListViewItem item = new ListViewItem(block.blockNum.ToString()); ListViewItem.ListViewSubItem type = new ListViewItem.ListViewSubItem(item, getDataFormatName(block.blockType)); ListViewItem.ListViewSubItem seq = new ListViewItem.ListViewSubItem(item, string.Format("{0:G}", block.seqNo)); ListViewItem.ListViewSubItem eraseCnt = new ListViewItem.ListViewSubItem(item, string.Format("{0:G}", block.eraseCnt)); ListViewItem.ListViewSubItem date = new ListViewItem.ListViewSubItem(item, string.Format("{0:0000}/{1:00}/{2:00}", block.lastEraseDate.year, block.lastEraseDate.month, block.lastEraseDate.day)); ListViewItem.ListViewSubItem time = new ListViewItem.ListViewSubItem(item, string.Format("{0:00}:{1:00}:{2:00}", block.lastEraseTime.hour, block.lastEraseTime.minute, block.lastEraseTime.second)); ListViewItem.ListViewSubItem size = new ListViewItem.ListViewSubItem(item, string.Format("{0:G}", block.recordSize)); ListViewItem.ListViewSubItem used = new ListViewItem.ListViewSubItem(item, (string.Format("{0:X}", block.used)).PadLeft(4, '0')); ListViewItem.ListViewSubItem saved = new ListViewItem.ListViewSubItem(item, (string.Format("{0:X}", block.saved)).PadLeft(4, '0')); item.SubItems.Insert(1, type); item.SubItems.Insert(2, seq); item.SubItems.Insert(3, eraseCnt); item.SubItems.Insert(4, date); item.SubItems.Insert(5, time); item.SubItems.Insert(6, size); item.SubItems.Insert(7, used); item.SubItems.Insert(8, saved); listView.Items.Add(item); } }
public static void updateListView(ListView lvToUse, ListViewItem lvItemToAdd) { if (lvToUse.InvokeRequired) { updateListViewCallback ulvCallback = new updateListViewCallback(updateListView); lvToUse.Invoke(ulvCallback, new object[] { lvToUse, lvItemToAdd }); } else { lvToUse.Items.Insert(0, lvItemToAdd); } }