Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Predictive Search within C# Windows Form?

Predictive Search within C# Windows Form?

Scheduled Pinned Locked Moved C#
questioncsharpdatabasecomdata-structures
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tkrn
    wrote on last edited by
    #1

    I can export the database part numbers into an array. I want to be able to search that array with predictive search. a good example is www.yahoo.com's search engine text box on the front page. How do i achieve this within a windows form and not in a web project. I've searched around for this but have not found much of anything useful. Thank you guys! Patrick!

    P I 2 Replies Last reply
    0
    • T tkrn

      I can export the database part numbers into an array. I want to be able to search that array with predictive search. a good example is www.yahoo.com's search engine text box on the front page. How do i achieve this within a windows form and not in a web project. I've searched around for this but have not found much of anything useful. Thank you guys! Patrick!

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      What have you been able to do so far?

      "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

      1 Reply Last reply
      0
      • T tkrn

        I can export the database part numbers into an array. I want to be able to search that array with predictive search. a good example is www.yahoo.com's search engine text box on the front page. How do i achieve this within a windows form and not in a web project. I've searched around for this but have not found much of anything useful. Thank you guys! Patrick!

        I Offline
        I Offline
        Ian Uy
        wrote on last edited by
        #3

        Have you tried using the Custom AutoComplete function of the textbox?

        It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

        T 1 Reply Last reply
        0
        • I Ian Uy

          Have you tried using the Custom AutoComplete function of the textbox?

          It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

          T Offline
          T Offline
          tkrn
          wrote on last edited by
          #4

          I did not even realize that the text box had autocomplete already. Thanks man! ran through my datagrid to make the textbox have a custom data source, but that took an awful long time to initialize due to 16K records. Any recommendations instead of a loop going through the datagridview of the first column then adding to the custom text box datasource for 16K records? Thank you sincerely once again!

          I 1 Reply Last reply
          0
          • T tkrn

            I did not even realize that the text box had autocomplete already. Thanks man! ran through my datagrid to make the textbox have a custom data source, but that took an awful long time to initialize due to 16K records. Any recommendations instead of a loop going through the datagridview of the first column then adding to the custom text box datasource for 16K records? Thank you sincerely once again!

            I Offline
            I Offline
            Ian Uy
            wrote on last edited by
            #5

            I don't know if this is the proper way to do it but I usually do it this way. 1. Create a Datatable 2. Fill the Datatable with the column of interest (Select COLUMN from Table) 3. Use a foreach loop to go thru each row 4. Use a StringBuilder to append those rows 5. Attatch the StringBuilder to the textbox. I usually doesn't any encounter a very long initialization time using this method. I used it in one of my OPAC projects.

            It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

            T 1 Reply Last reply
            0
            • I Ian Uy

              I don't know if this is the proper way to do it but I usually do it this way. 1. Create a Datatable 2. Fill the Datatable with the column of interest (Select COLUMN from Table) 3. Use a foreach loop to go thru each row 4. Use a StringBuilder to append those rows 5. Attatch the StringBuilder to the textbox. I usually doesn't any encounter a very long initialization time using this method. I used it in one of my OPAC projects.

              It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

              T Offline
              T Offline
              tkrn
              wrote on last edited by
              #6

              Below is the code i used for the autocomplete text box to search through the records and focus on the record closest matched which is scrolled to in the list automatically. What do you think!? ---- private void txtSearchbyPN_KeyUp(object sender, KeyEventArgs e) { string searchStr = txtSearchbyPN.Text.ToString(); int searchLen = txtSearchbyPN.Text.Length; for (int i = 0; i < cachedPartNumbers.Length; i++) { if (cachedPartNumbers[i].Length >= searchLen) { if (searchStr.Equals(((cachedPartNumbers[i].ToString()).Substring(0, searchLen)))) { locationInArray = i; break; } } } dgMainForm.CurrentCell = dgMainForm.Rows[locationInArray].Cells[0]; }

              L 1 Reply Last reply
              0
              • T tkrn

                Below is the code i used for the autocomplete text box to search through the records and focus on the record closest matched which is scrolled to in the list automatically. What do you think!? ---- private void txtSearchbyPN_KeyUp(object sender, KeyEventArgs e) { string searchStr = txtSearchbyPN.Text.ToString(); int searchLen = txtSearchbyPN.Text.Length; for (int i = 0; i < cachedPartNumbers.Length; i++) { if (cachedPartNumbers[i].Length >= searchLen) { if (searchStr.Equals(((cachedPartNumbers[i].ToString()).Substring(0, searchLen)))) { locationInArray = i; break; } } } dgMainForm.CurrentCell = dgMainForm.Rows[locationInArray].Cells[0]; }

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Hi, Two comments: 1. I suggest you have a look at String.StartsWith() 2. You might want to store the results of cachedPartNumbers[i].ToString() rather than calling it all the time :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Voting for dummies? No thanks. X|


                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups