private void UpdatePlayerList(IPAddress sourceIP, IPAddress destinationIP) { ListView.ListViewItemCollection playerItems = toolUI.playerList.Items; //Update the source if (playerItems.ContainsKey(sourceIP.ToString())) { ((ListViewPlayerItem)playerItems[sourceIP.ToString()]).PlayerLastTime = DateTime.Now; } else { playerItems.Add(new ListViewPlayerItem(lookupService, sourceIP)); } //Update the destination if (playerItems.ContainsKey(destinationIP.ToString())) { ((ListViewPlayerItem)playerItems[destinationIP.ToString()]).PlayerLastTime = DateTime.Now; } else { playerItems.Add(new ListViewPlayerItem(lookupService, destinationIP)); } //Update entries foreach (ListViewPlayerItem playerItem in playerItems) { if (partystatePlayers.ContainsKey(IPAddress.Parse(playerItem.PlayerIP))) { playerItem.PartystatePlayer = partystatePlayers[IPAddress.Parse(playerItem.PlayerIP)]; } } }
protected string CheckStringValue(ListView.ListViewItemCollection collection, RegistryKey rk, string value, DataEntry[] de) { if (rk == null) { return(null); } try { RegistryValueKind k = rk.GetValueKind(value); if (k != RegistryValueKind.String && k != RegistryValueKind.ExpandString) { collection.Add(this, "Incorrect type of the registry value.", de, new DataEntry("Value Name", value ?? "(default)"), new DataEntry("Key", rk.ToString()), new DataEntry("Expected Kind", new RegistryValueKind[] { RegistryValueKind.ExpandString, RegistryValueKind.String }), new DataEntry("Actual Kind", k)); return(null); } else { string res = rk.GetValue(value, null, RegistryValueOptions.DoNotExpandEnvironmentNames) as string; if (string.IsNullOrEmpty(res)) { collection.Add(this, "Empty value is specified.", de, new DataEntry("Value", value ?? "(default)"), new DataEntry("Key", rk.ToString())); } return(res); } } catch (IOException) { collection.Add(this, "The registry value is missing.", de, new DataEntry("Value Name", value ?? "(default)"), new DataEntry("Key", rk.ToString())); return(null); } }
public void LoadListView(ListView listView, ImageList imageList, string remotePath) { if (upYun == null) { return; } Cursor.Current = Cursors.WaitCursor; List <FolderItem> itemsArray = new List <FolderItem>(); try { itemsArray = upYun.readDir(remotePath).Cast <FolderItem>().ToList(); } catch { } // UpYun SDK BUG: 调用readDir方法时,如果该目录下没有任何文件或目录,会有数组越界的问题 try { ListView.ListViewItemCollection listViewItems = listView.Items; int imageIndex = 0; string programPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); ImageList.ImageCollection imageItems = imageList.Images; listViewItems.Clear(); imageItems.Clear(); if (!remotePath.Equals("/")) { string[] itemInfo = new string[4]; itemInfo[0] = "上级目录"; itemInfo[3] = "ParentDir"; ListViewItem parentDirItem = new ListViewItem(itemInfo, 0); listViewItems.Add(parentDirItem); imageItems.Add(StaticFileUpload.Business.Properties.Resources.up_16x16); imageIndex++; } imageItems.Add(IconUtil.GetDirectoryIcon(programPath)); imageIndex++; foreach (FolderItem item in itemsArray) { ListViewItem listViewItem = null; string[] itemInfo = new string[4]; itemInfo[0] = item.filename; itemInfo[1] = SFUCommon.GetCommonSize(item.size); itemInfo[2] = SFUCommon.GetCommonTime(item.number).ToString(); if (item.filetype.Equals("N")) { itemInfo[3] = "N"; listViewItem = new ListViewItem(itemInfo, imageIndex); imageItems.Add(IconUtil.GetFileIcon(item.filename, false)); imageIndex++; } else { itemInfo[3] = "F"; listViewItem = new ListViewItem(itemInfo, remotePath.Equals("/") ? 0 : 1); } listViewItems.Add(listViewItem); } } catch (Exception ex) { SFULogger.DEFAULT.Error(ex); throw; } Cursor.Current = Cursors.Default; }
public void LoadListView(ListView listView, ImageList imageList, string localPath) { Cursor.Current = Cursors.WaitCursor; string[] filesArray, diresArray; int imageIndex = 1; ListView.ListViewItemCollection listViewItems = listView.Items; ImageList.ImageCollection imageListItems = imageList.Images; try { diresArray = Directory.GetDirectories(localPath); filesArray = Directory.GetFiles(localPath); } catch (Exception ex) { SFULogger.DEFAULT.Error("该目录不存在!", ex); MessageBox.Show("该目录不存在!"); return; } // 清空 ListView & ImageList 控件条目集合 listViewItems.Clear(); imageListItems.Clear(); listViewItems.Add("上级目录", 0); imageListItems.Add(StaticFileUpload.Business.Properties.Resources.up_16x16); // 遍历 localPath 目录下的子文件夹 for (int i = 0; i < diresArray.Length; i++) { string[] dirInfoArray = new string[3]; DirectoryInfo directoryInfo = new DirectoryInfo(diresArray[i]); if ((directoryInfo.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { dirInfoArray[0] = directoryInfo.Name; dirInfoArray[1] = " "; dirInfoArray[2] = directoryInfo.LastWriteTime.ToString(); ListViewItem listViewItem = new ListViewItem(dirInfoArray, imageIndex); listViewItems.Add(listViewItem); imageListItems.Add(dirInfoArray[0], IconUtil.GetDirectoryIcon(directoryInfo.FullName)); imageIndex++; } } // 遍历 localPath 目录下的子文件 for (int i = 0; i < filesArray.Length; i++) { string[] fileInfoArray = new string[3]; FileInfo fileInfo = new FileInfo(filesArray[i]); if ((fileInfo.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { fileInfoArray[0] = fileInfo.Name; fileInfoArray[1] = SFUCommon.GetCommonSize(fileInfo.Length); fileInfoArray[2] = fileInfo.LastWriteTime.ToString(); ListViewItem listViewItem = new ListViewItem(fileInfoArray, imageIndex); listViewItems.Add(listViewItem); imageListItems.Add(fileInfo.Name, IconUtil.GetFileIcon(fileInfo.FullName, false)); imageIndex++; } } Cursor.Current = Cursors.Default; }
public void ListViewItemCollection_Find_InvokeKeyExists_ReturnsExpected(string key) { using ListView listView = new ListView(); var child1 = new ListViewItem { Name = "name1" }; var child2 = new ListViewItem { Name = "name2" }; var child3 = new ListViewItem { Name = "name2" }; var grandchild1 = new ListViewItem.ListViewSubItem { Name = "name1" }; var grandchild2 = new ListViewItem.ListViewSubItem { Name = "name2" }; var grandchild3 = new ListViewItem.ListViewSubItem { Name = "name2" }; ListView.ListViewItemCollection collection = listView.Items; child3.SubItems.Add(grandchild1); child3.SubItems.Add(grandchild2); child3.SubItems.Add(grandchild3); collection.Add(child1); collection.Add(child2); collection.Add(child3); // Search all subitems. Assert.Equal(new ListViewItem[] { child2, child3 }, collection.Find(key, searchAllSubItems: true)); // Call again. Assert.Equal(new ListViewItem[] { child2, child3 }, collection.Find(key, searchAllSubItems: true)); // Don't search all subitems. Assert.Equal(new ListViewItem[] { child2, child3 }, collection.Find(key, searchAllSubItems: false)); // Call again. Assert.Equal(new ListViewItem[] { child2, child3 }, collection.Find(key, searchAllSubItems: false)); }
private void FillListItems(ListView.ListViewItemCollection items, string path) { items.Clear(); try { DirectoryInfo root = new DirectoryInfo(path); foreach (FileInfo file in root.GetFiles()) { ShellFileInfo finfo = new ShellFileInfo(file.FullName); string[] strs = { file.Name, Convert.ToString(file.Length / 1024) + "KB", finfo.FileType() }; ListViewItem item = new ListViewItem(strs); string key = finfo.IconIndex().ToString(); if (!iconsList.Images.ContainsKey(key)) { iconsList.Images.Add(key, finfo.FileIcon()); } item.ImageKey = key; item.Tag = file.FullName; items.Add(item); } } catch { } }
public static void BrowseHandler(TextBox tbPath, ListView.ListViewItemCollection items) { var fd = new FolderBrowserDialog(); fd.RootFolder = Environment.SpecialFolder.MyComputer; if (!Directory.Exists(tbPath.Text)) { if (fd.ShowDialog() != DialogResult.OK) { return; } tbPath.Text = fd.SelectedPath; } items.Clear(); var wmp = new WindowsMediaPlayer(); var exts = new Regex(@"\.(mp[234a]|m4a|aac|mka|wma|wav|flac)$"); var audios = Directory.EnumerateFiles(tbPath.Text).Where(x => exts.IsMatch(x)); foreach (var file in audios) { TrackMetadata meta = GetMetadata(wmp, file); items.Add(new ListViewItem(meta.ListItem) { Tag = meta }); } }
/// <summary> /// 指定アイテムを追加する /// </summary> /// <param name="itemType">リストアイテム種別</param> /// <param name="lvItems">追加するリストビューアイテムコレクション</param> public void AddLVItem(string itemType, ListView.ListViewItemCollection lvItems) { switch (itemType) { case "火力": case "対空": case "装甲": case "雷装": case "回避": case "索敵": case "対潜": case "HP": case "燃料": case "弾薬": case "運": case "速力": case "射程": var lvit = GetLVItem(itemType); if (lvit != null) { lvItems.Add(lvit); } return; case "装備": AddSlotItems(lvItems); return; default: throw new ArgumentOutOfRangeException(string.Format("not defined type:[{0}]", itemType)); // return; } }
public void LoadListViewByMyPcPath(ListView listView, ImageList imageList, string myPcPath) { Cursor.Current = Cursors.WaitCursor; ListView.ListViewItemCollection listViewItems = listView.Items; ImageList.ImageCollection imageListItems = imageList.Images; listViewItems.Clear(); imageListItems.Clear(); string[] dirsArray; int imageIndex = 0; try { dirsArray = Directory.GetLogicalDrives(); for (int i = 0; i < dirsArray.Length; i++) { DriveInfo driInfo = new DriveInfo(dirsArray[i]); string[] driInfoArray = new string[4]; driInfoArray[0] = string.Format("{0}({1})", driInfo.VolumeLabel, driInfo.Name); driInfoArray[1] = SFUCommon.GetCommonSize(driInfo.TotalSize); driInfoArray[2] = SFUCommon.GetCommonSize(driInfo.TotalFreeSpace); driInfoArray[3] = driInfo.Name; ListViewItem listViewItem = new ListViewItem(driInfoArray, imageIndex); listViewItems.Add(listViewItem); imageListItems.Add(IconUtil.GetDirectoryIcon(driInfo.Name)); imageIndex++; } } catch (Exception) { //如果不使用try catch抓取错误并以此跳过错误,在添加没有放入光盘的光驱Items时会提示错误 } Cursor.Current = Cursors.Default; }
private void FillShoppingList() { string[] strListEntry = new string[3]; ListViewItem temp = new ListViewItem(); for (int i = 0; i < Program.iMasterListIDs.Count; i++) { strListEntry[0] = Program.strMasterListNames[i]; strListEntry[1] = Program.iMasterListCount[i].ToString(); strListEntry[2] = Program.iMasterListPrice[i].ToString(); temp = new ListViewItem(strListEntry); listMaster.Add(temp); } //listShoppingList.Items.AddRange( = items; int tC, tS, tG; int totalPrice = Program.totalPrice; tG = totalPrice / 10000; totalPrice = totalPrice % 10000; tS = totalPrice / 100; tC = totalPrice % 100; lblTotalCost.Text = string.Format("{0}g {1}s {2}c", tG, tS, tC); }
public static ListViewItem Add(this ListView.ListViewItemCollection src, params object[] Values) { ListViewItem lvi = new ListViewItem(Values.Select(x => x.ToString()).ToArray()); src.Add(lvi); return(lvi); }
public void SetHostEntries(IEnumerable <HostEntryViewModel> hostEntries) { int[] selectedIndicies = this.ListView.SelectedIndices.OfType <int>().ToArray(); ListView.ListViewItemCollection items = ListView.Items; items.Clear(); var newEntries = hostEntries.Select(CreateListViewItem); foreach (ListViewItem item in newEntries) { items.Add(item); } for (int i = 0; i < selectedIndicies.Length; i++) { int selectedIndex = selectedIndicies[i]; if (selectedIndex < items.Count) { items[selectedIndex].Selected = true; } } this.Update(); }
public static void Add(this ListView.ListViewItemCollection col, RenameItem i) { var lvi = new ListViewItem(new[] { i.Path, i.Info.CreationTime.ToShortDateString(), i.Info.LastWriteTime.ToShortDateString(), i.OldName, i.NewName }); lvi.Tag = i; col.Add(lvi); }
public Graphic(int[][] _table, int[] _sequence) { table = _table; sequnce = _sequence; tmp = Algorithm.matrixMethod(table); downtimes = countDowntimes(); InitializeComponent(); Color[] colors = GetColors(); ListView.ListViewItemCollection items = detailsViewBox.Items; items.Add("Простой"); items[0].BackColor = colors[0]; for (int i = 0; i < sequnce.Length; i++) { items.Add((sequnce[i] + 1).ToString() + "-я деталь").BackColor = colors[sequnce[i] + 1]; } }
private void init_dlg() { ListView.ListViewItemCollection items = lv_confs.Items; items.Clear(); if (m_proj == null) { Text = "Project configuration"; } else { Text = "Project '" + m_proj_name + "' (" + m_proj_ver + ") configuration"; XmlNodeList confs = m_proj.GetElementsByTagName("Configuration"); for (int i = 0; i < confs.Count; ++i) { XmlNode conf = confs[i]; ListViewItem item = prepare_item(conf); items.Add(item); } if (confs.Count > 0) { lv_confs.Items[0].Selected = true; } } }
public static void AddObjects(LevelArea area, List <Managed3DObject> objList, IEnumerable <Managed3DObject> objs, ListView.ListViewItemCollection lvic, IEnumerable <ListViewItem> lvis) { for (int i = 0, loopTo = objs.Count() - 1; i <= loopTo; i++) { area.Objects.Add(objs.ElementAtOrDefault(i).Command); objList.Add(objs.ElementAtOrDefault(i)); lvic.Add(lvis.ElementAtOrDefault(i)); } }
public void AddItem(Alarm alarm) { if (!dic_instance_item.ContainsKey(alarm.instance)) { dic_instance_item.Add(alarm.instance, CreateListViewItem(alarm)); //Add the items to the ListView. listviewitems.Add(dic_instance_item[alarm.instance]); } }
public static void AddWarps(LevelArea area, List <IManagedLevelscriptCommand> objList, IEnumerable <IManagedLevelscriptCommand> objs, ListView.ListViewItemCollection lvic, IEnumerable <ListViewItem> lvis, Dictionary <ListViewItem, ListViewGroup> lviGroups) { for (int i = 0, loopTo = objs.Count() - 1; i <= loopTo; i++) { area.Objects.Add(objs.ElementAtOrDefault(i).Command); objList.Add(objs.ElementAtOrDefault(i)); var lvi = lvis.ElementAtOrDefault(i); lvi.Group = lviGroups[lvi]; lvic.Add(lvi); } }
private void setAllFilesInListView() { ListView.ListViewItemCollection list = listView1.Items; string[] files = Directory.GetFiles(pathDirWithMedialFiles, "*.wav"); foreach (string file in files) { associateArray.Add(associateArray.Count + 1); list.Add(file); } Sorting(); }
internal static void AddWithTextAndSubItems(this ListView.ListViewItemCollection col, string text, params string[] subItems) { var item = new ListViewItem(text); foreach (var subItem in subItems) { item.SubItems.Add(subItem); } col.Add(item); }
/*private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e) { * if (e.Item.Checked) { // afiseaza * for (int i = 0; i < this.ALL_ITEMS.Count; i++) { * //MessageBox.Show(itm.SubItems[INDEX].Text); * if (this.ALL_ITEMS[i].SubItems[INDEX].Text == e.Item.Text) { * LV_ITEMS.Add(this.ALL_ITEMS[i].Text); * for(int j = 1;j< this.ALL_ITEMS[i].SubItems.Count;j++) * LV_ITEMS[LV_ITEMS.Count - 1].SubItems.Add(this.ALL_ITEMS[i].SubItems[j].Text); * LV_ITEMS[LV_ITEMS.Count - 1].Checked = false; * } * } * } else { // ascunde * foreach (ListViewItem lvi in LV_ITEMS) * if (lvi.SubItems[INDEX].Text == e.Item.Text) * LV_ITEMS.Remove(lvi); * } * }*/ public static ListView.ListViewItemCollection cloneItems(ListView.ListViewItemCollection items) { ListView.ListViewItemCollection newItems = new ListView.ListViewItemCollection(new ListView()); foreach (ListViewItem listViewItem in items) { newItems.Add(cloneItem(listViewItem)); } return(newItems); }
/// <summary> /// Converts the current AudioTaskItemCollection to ListViewItemCollection. /// </summary> /// <param name="listView">The owner ListView.</param> /// <returns>The converted ListViewItemCollection</returns> public ListView.ListViewItemCollection ToListViewItemCollection(ListView listView) { listView.Items.Clear(); var listItems = new ListView.ListViewItemCollection(listView); foreach (var audioTaskItem in Items) { listItems.Add(audioTaskItem.ToListViewItem()); } return(listItems); }
protected void CheckValue(ListView.ListViewItemCollection collection, RegistryKey rk, string value, string[] valid, DataEntry[] de) { string v = CheckStringValue(collection, rk, value, de); if (!string.IsNullOrEmpty(v)) { if (Array.FindIndex(valid, delegate(string obj) { return(string.Compare(v, obj, StringComparison.OrdinalIgnoreCase) == 0); }) < 0) { collection.Add(this, "Unexpected value is specified.", de, new DataEntry("Actual Value", v), new DataEntry("Expected Values", valid), new DataEntry("Key", rk.ToString())); } } }
private void update_view() { this.TrapList.Items.Clear(); if (this.fTrapElement == null) { return; } ListView.ListViewItemCollection items = this.TrapList.Items; object[] name = new object[] { this.fTrapElement.Trap.Name, ": ", this.fTrapElement.GetXP(), " XP" }; ListViewItem item = items.Add(string.Concat(name)); item.Group = this.TrapList.Groups[0]; ListViewItem listViewItem = this.TrapList.Items.Add(this.fTrapElement.Trap.Info); listViewItem.Group = this.TrapList.Groups[0]; if (this.fTrapElement.MapID != Guid.Empty) { Map map = Session.Project.FindTacticalMap(this.fTrapElement.MapID); MapArea mapArea = map.FindArea(this.fTrapElement.MapAreaID); string str = string.Concat("Location: ", map.Name); if (mapArea != null) { str = string.Concat(str, " (", mapArea.Name, ")"); } ListViewItem item1 = this.TrapList.Items.Add(str); item1.Group = this.TrapList.Groups[0]; } foreach (TrapSkillData skill in this.fTrapElement.Trap.Skills) { ListViewItem listViewItem1 = this.TrapList.Items.Add(skill.ToString()); listViewItem1.Group = this.TrapList.Groups[1]; listViewItem1.Tag = skill; } if (this.fTrapElement.Trap.Skills.Count == 0) { ListViewItem grayText = this.TrapList.Items.Add("(no skills)"); grayText.Group = this.TrapList.Groups[1]; grayText.ForeColor = SystemColors.GrayText; } foreach (string countermeasure in this.fTrapElement.Trap.Countermeasures) { ListViewItem item2 = this.TrapList.Items.Add(countermeasure); item2.Group = this.TrapList.Groups[2]; item2.Tag = countermeasure; } if (this.fTrapElement.Trap.Countermeasures.Count == 0) { ListViewItem grayText1 = this.TrapList.Items.Add("(no countermeasures)"); grayText1.Group = this.TrapList.Groups[2]; grayText1.ForeColor = SystemColors.GrayText; } }
/// <summary> /// 装備情報を追加 /// </summary> /// <param name="lvItems"></param> void AddSlotItems(ListView.ListViewItemCollection lvItems) { for (int n = 0; n < _info.SlotNum; n++) { string name = string.Format("装備{0}", n + 1); //有効スロットの場合 if (_info.SlotItem.Count > n) { //艦載機の場合 if (_info.SlotItem[n].Count > 0) { name = string.Format("装備{0} x{1}", n + 1, _info.SlotItem[n].Count); } lvItems.Add(new SlotItemLVItem(name, _info.SlotItem[n], _imgSlotItem)); } else { lvItems.Add(new ListViewItem(new string[] { name, "(装備不可)" })); } } }
public void LoadTaskList(ListView.ListViewItemCollection listViewTasks, ListViewGroupCollection listViewGroup, string loadFolder) { try { StreamReader file = new StreamReader(loadFolder + @"\pomodomo_save.dom"); string line; string[] words; ListViewItem newItem; while ((line = file.ReadLine()) != null) { // We then split the line at the ';' character words = line.Split(';'); // We add this to the listView newItem = listViewTasks.Add(words[0]); // We then add the deadline newItem.SubItems.Add(words[1]); // We then add the prioirty newItem.SubItems.Add(words[2]); if (words[3] == "Other Tasks") { newItem.Group = listViewGroup[1]; } else if (words[3] == "Today") { newItem.Group = listViewGroup[0]; } else if (words[3] == "Completed") { newItem.Group = listViewGroup[2]; } } file.Close(); } catch { MessageBox.Show("Couldn't load the task list file from directory " + loadFolder + @"\pomodomo_save.dom", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); } }
protected RegistryKey OpenSubKey(ListView.ListViewItemCollection collection, RegistryKey rk, string name, DataEntry[] de) { if (rk == null) { return(null); } RegistryKey res = rk.OpenSubKey(name); if (res == null) { collection.Add(this, "Registry key is missing.", de, new DataEntry("Key", string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", rk, name))); } return(res); }
public void Show() { ListView.ListViewItemCollection itemCollection = Program.Form.torrentListView.Items; if (!itemCollection.Contains(this)) { lock (Program.Form.torrentListView) { if (!itemCollection.Contains(this)) { UpdateUi(false); itemCollection.Add(this); } } } }
public static void UpdateDirectories(ListView.ListViewItemCollection list, string path) { DirectoryInfo di = new DirectoryInfo(path); DirectoryInfo[] directories = di.GetDirectories(); foreach (DirectoryInfo info in directories) { ListViewItem lvi = new ListViewItem(); lvi.ImageIndex = 1; lvi.Text = info.Name; lvi.Tag = "directory"; list.Add(lvi); } }
public static void UpdateFiles(ListView.ListViewItemCollection list, string pat) { DirectoryInfo di = new DirectoryInfo(pat); FileInfo[] files = di.GetFiles(); foreach (FileInfo info in files) { ListViewItem lvi = new ListViewItem(); lvi.ImageIndex = 0; lvi.Text = info.Name; lvi.Tag = "file"; list.Add(lvi); } }