FindItemWithText() public method

public FindItemWithText ( string text ) : System.Windows.Forms.ListViewItem
text string
return System.Windows.Forms.ListViewItem
Example #1
0
        private Boolean AddItemToListView(ListView listView, String path)
        {
            if (null != listView.FindItemWithText(path))
            {
                return false;
            }

            ListViewItem lvi = new ListViewItem((listView.Items.Count + 1).ToString());

            lvi.SubItems.Add(""); // 완료 여부 컬럼 - 처음에는 빈칸을 넣는다.
            lvi.SubItems.Add(path); //파일 경로

            // 기본적으로 파일 생성날짜를 읽어온다.
            // Exif가 존재한다면 아래 로직에서 Exif에서 생성된 날짜를 읽어온다.
            FileInfo fileInfo = new FileInfo(path);
            String fileCreationTime = fileInfo.LastWriteTime.Date.ToString("yyyy-MM-dd").Substring(0, 10);

            // Exif 지원 확장자인 경우 Exif에서 생성된 날짜를 읽어온다.
            if (true == IsExifSupportExtension(path))
            {
                 String exifDate = GetExifDate(path);

                if (false == String.IsNullOrEmpty(exifDate))
                {
                    exifDate = exifDate.Substring(0, 10);
                    fileCreationTime = exifDate;
                }
            }

            lvi.SubItems.Add(fileCreationTime); // 생성 날짜

            long fileSize = fileInfo.Length;
            // 파일 크기
            if (0 == fileSize)
                lvi.SubItems.Add("0 KB");
            else if (1024 > fileSize)
                lvi.SubItems.Add("1 KB");
            else if (1048576 > fileSize)
                lvi.SubItems.Add(String.Format("{0:N}", (double)(fileSize / 1024)) + " KB");
            else if (1073741824 > fileSize)
                lvi.SubItems.Add(String.Format("{0:N}", (double)(fileSize / 1048576)) + " MB");
            else
                lvi.SubItems.Add(String.Format("{0:N}", (double)(fileSize / 1073741824)) + " GB");

            listView.Items.Add(lvi);
            return true;
        }
Example #2
0
		public void FindItemWithText_Exceptions ()
		{
			ListView lvw = new ListView ();

			// Shouldn't throw any exception
			lvw.FindItemWithText (null);

			try {
				lvw.FindItemWithText (null, false, 0);
				Assert.Fail ("#A1");
			} catch (ArgumentOutOfRangeException) {
			}

			try {
				lvw.FindItemWithText (null, false, lvw.Items.Count);
				Assert.Fail ("#A2");
			} catch (ArgumentOutOfRangeException) {
			}

			// Add a single item
			lvw.Items.Add ("bracket");

			try {
				lvw.FindItemWithText (null);
				Assert.Fail ("#A3");
			} catch (ArgumentNullException) {
			}

			try {
				lvw.FindItemWithText ("bracket", false, -1);
				Assert.Fail ("#A4");
			} catch (ArgumentOutOfRangeException) {
			}

			try {
				lvw.FindItemWithText ("bracket", false, lvw.Items.Count);
				Assert.Fail ("#A5");
			} catch (ArgumentOutOfRangeException) {
			}
		}
Example #3
0
		public void FindItemWithText ()
		{
			ListView lvw = new ListView();
			ListViewItem lvi1 = new ListViewItem (String.Empty);
			ListViewItem lvi2 = new ListViewItem ("angle bracket");
			ListViewItem lvi3 = new ListViewItem ("bracket holder");
			ListViewItem lvi4 = new ListViewItem ("bracket");
			lvw.Items.AddRange (new ListViewItem [] { lvi1, lvi2, lvi3, lvi4 });

			Assert.AreEqual (lvi1, lvw.FindItemWithText (String.Empty), "#A1");
			Assert.AreEqual (lvi3, lvw.FindItemWithText ("bracket"), "#A2");
			Assert.AreEqual (lvi3, lvw.FindItemWithText ("BrackeT"), "#A3");
			Assert.IsNull (lvw.FindItemWithText ("holder"), "#A5");

			Assert.AreEqual (lvw.Items [3], lvw.FindItemWithText ("bracket", true, 3), "#B1");

			Assert.AreEqual (lvw.Items [2], lvw.FindItemWithText ("bracket", true, 0, true), "#C1");
			Assert.AreEqual (lvw.Items [3], lvw.FindItemWithText ("bracket", true, 0, false), "#C2");
			Assert.AreEqual(lvw.Items [3], lvw.FindItemWithText("BrackeT", true, 0, false), "#C3");
			Assert.IsNull (lvw.FindItemWithText ("brack", true, 0, false), "#C4");

			// Sub item search tests
			lvw.Items.Clear ();

			lvi1.Text = "A";
			lvi1.SubItems.Add ("car bracket");
			lvi1.SubItems.Add ("C");

			lvi2.Text = "B";
			lvi2.SubItems.Add ("car");

			lvi3.Text = "C";

			lvw.Items.AddRange (new ListViewItem [] { lvi1, lvi2, lvi3 });

			Assert.AreEqual (lvi1, lvw.FindItemWithText ("car", true, 0), "#D1");
			Assert.AreEqual (lvi3, lvw.FindItemWithText ("C", true, 0), "#D2");
			Assert.AreEqual (lvi2, lvw.FindItemWithText ("car", true, 1), "#D3");
			Assert.IsNull (lvw.FindItemWithText ("car", false, 0), "#D4");

			Assert.AreEqual (lvi1, lvw.FindItemWithText ("car", true, 0, true), "#E1");
			Assert.AreEqual (lvi2, lvw.FindItemWithText ("car", true, 0, false), "#E2");
			Assert.AreEqual (lvi2, lvw.FindItemWithText ("CaR", true, 0, false), "#E3");
		}
Example #4
0
        public void Populate(string classification)
        {
            CurrentClassification            = classification;
            mCurrentClassificationProperties = new MOG_Properties(CurrentClassification);

            // For speed purposes, create 3 HybridDictionary lists
            // Populate the files that exist on the local hardrive
            string drivePath = Path.Combine(MOG_ControllerLibrary.GetWorkingDirectory(), MOG_Filename.GetClassificationPath(classification));

            string[] files = new string[] { };
            if (DosUtils.DirectoryExistFast(drivePath))
            {
                files = Directory.GetFiles(drivePath);
            }
            HybridDictionary filesOnDisk = new HybridDictionary();

            foreach (string file in files)
            {
                filesOnDisk[Path.GetFileName(file)] = file;
            }
            // Populate the assets that exist in MOG
            ArrayList        assets      = MOG_ControllerAsset.GetAssetsByClassification(classification);
            HybridDictionary assetsInMOG = new HybridDictionary();

            foreach (MOG_Filename asset in assets)
            {
                assetsInMOG[asset.GetAssetLabel()] = asset;
            }
            // Create a master list
            HybridDictionary masterList = new HybridDictionary();

            foreach (string file in filesOnDisk.Values)
            {
                masterList[Path.GetFileName(file)] = Path.GetFileName(file);
            }
            foreach (MOG_Filename asset in assetsInMOG.Values)
            {
                masterList[asset.GetAssetLabel()] = asset.GetAssetLabel();
            }


            // Rebuild our LibraryListView
            LibraryListView.BeginUpdate();
            mLibrarySortManager.SortEnabled = false;

            LibraryListView.Items.Clear();

            foreach (string file in masterList.Keys)
            {
                // Check if this file is in MOG?
                if (assetsInMOG.Contains(file))
                {
                    MOG_Filename asset = assetsInMOG[file] as MOG_Filename;

                    // Create the ListView item  for this asset
                    ListViewItem item = CreateListViewItemForAsset(asset);
                    LibraryListView.Items.Add(item);
                }
                else
                {
                    string fullFilename = filesOnDisk[file] as string;
                    bool   bIsValid     = true;

                    // Check the classification's inclusion filter.
                    if (mCurrentClassificationProperties.FilterInclusions.Length > 0)
                    {
                        MOG.FilePattern inclusions = new MOG.FilePattern(mCurrentClassificationProperties.FilterInclusions);
                        if (inclusions.IsFilePatternMatch(Path.GetFileName(fullFilename)) == false)
                        {
                            bIsValid = false;
                        }
                    }
                    // Check the classification's exclusion filter.
                    if (mCurrentClassificationProperties.FilterExclusions.Length > 0)
                    {
                        MOG.FilePattern exclusions = new MOG.FilePattern(mCurrentClassificationProperties.FilterExclusions);
                        if (exclusions.IsFilePatternMatch(Path.GetFileName(fullFilename)) == true)
                        {
                            bIsValid = false;
                        }
                    }

                    // Check if we determined this to be a valid file to show?
                    if (bIsValid)
                    {
                        ListViewItem item = CreateListViewItemForFile(fullFilename);
                        UpdateListViewItemColors(item, "Unknown");
                        LibraryListView.Items.Add(item);
                    }
                }
            }

            mLibrarySortManager.SortEnabled = true;
            LibraryListView.EndUpdate();

            // Check if we have a mLastTopItem specified?
            if (mLastTopItem.Length > 0)
            {
                LibraryListView.TopItem = LibraryListView.FindItemWithText(mLastTopItem);
                mLastTopItem            = "";
            }
        }
Example #5
0
 private bool medicationOrSupplementExistInTheList(ListView listView, String value)
 {
     return listView.FindItemWithText(value) != null;
 }
Example #6
0
 /// <summary>
 /// General function to search any list view form. Highlights rows with matches.
 /// </summary>
 /// <param name="needle">String to search for</param>
 /// <param name="haystack">ListView object to search in</param>
 private void searchList(string needle, ListView haystack)
 {
     if (haystack.Items.Count > 0)
     {
         // Focus the list view
         haystack.Focus();
         // Clear currently selected items
         haystack.SelectedItems.Clear();
         int i = 0;
         ListViewItem found;
         do
         {
             // Recursively find all instances of the given text, starting from zero
             found = haystack.FindItemWithText(needle, true, i, true);
             if (found != null)
             {
                 // Select found item
                 found.Selected = true;
                 // Next search starts from the next element in the list view
                 i = found.Index + 1;
             }
             else
             {
                 // Otherwise, stop
                 i = haystack.Items.Count;
             }
         } while (i < haystack.Items.Count);
     }
     // If nothing found, show message
     if (haystack.SelectedItems.Count == 0)
     {
         MessageBox.Show("Value could not be found.", "Search", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        public bool hasNSTP(ListView lv)
        {
            bool isTrue = false;
            if (lv.FindItemWithText("CWTS/ROTC").Index > 0)
            {
                isTrue = true;
                hasNSTPPick = true;
            }

            return isTrue;
        }
Example #8
0
 //funciones
 public static void Buscar_ListView(ListView LV, string sValor, Boolean bSubItems)
 {
     ListViewItem foundItem = new ListViewItem();
     foundItem = LV.FindItemWithText(sValor, bSubItems, 0, true);
     if (foundItem != null)
     {
         LV.HideSelection = false;
         LV.Items[foundItem.Index].Selected = true;
         LV.Items[foundItem.Index].EnsureVisible();
     }
 }
        private void ScanFirmwareDirectory()
        {
            // Apparently stop and start is a typical way of resetting the timer
            // We want to reset the timer here
            ScanTimer.Stop();

            // hexlist_buffer is not used in main thread
            hexList_buffer = new ListView();

            list_sorting(false); // disable sorting while we re-populate

            ProcessDirectory("\\\\wpgfile01\\EDC\\Firmware\\Price"); // fill the list

            // Move the data from buffer to the actual hex list
            // Since we might be in a different thread, this will need to use the invoke call
            list_clear();

            // No filter
            if (string.IsNullOrWhiteSpace(FilterBox.Text))
            {
                foreach (ListViewItem item in hexList_buffer.Items)
                {
                    // Transfer from buffer to the real displayed hexlist
                    list_add((ListViewItem)item.Clone());
                    //ShowTimerEventFired((ListViewItem)item.Clone());
                }
            }
            else
            {
                // Find all keywords
                string[] key_words = FilterBox.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                // Trim off all spaces, just in case
                for (var i = 0; i < key_words.Length; i++)
                    key_words[i] = key_words[i].Trim();

                // Get all matches
                ListViewItem item_buffer = new ListViewItem();
                foreach (string key_word in key_words)
                {
                    var i = 0;
                    while ((item_buffer = hexList_buffer.FindItemWithText(key_word, false, i)) != null && !string.IsNullOrEmpty(key_word))
                    {
                        // Implent the Start Index for the finder
                        i = item_buffer.Index + 1;

                        //Put the finding into the list
                        list_add((ListViewItem)item_buffer.Clone());
                        //ShowTimerEventFired((ListViewItem)item_buffer.Clone());
                    }
                }
            }

            // Resume the sorting, since we finished building the list
            list_sorting(true);

            // We want to reset the timer here
            ScanTimer.Start();
        }