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. C# Datagrid Search

C# Datagrid Search

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
5 Posts 3 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.
  • G Offline
    G Offline
    Gammaza
    wrote on last edited by
    #1

    Hi everyone.... Can anyone tell me if its possible to autosearch a datagrid if the user starts typing on it ? For example if the user starts typing in a Code field, the datagrid must go to the first location equal to the character pressed etc. until a code is found. Keypressed property ?? Please need help ! :((

    T R 2 Replies Last reply
    0
    • G Gammaza

      Hi everyone.... Can anyone tell me if its possible to autosearch a datagrid if the user starts typing on it ? For example if the user starts typing in a Code field, the datagrid must go to the first location equal to the character pressed etc. until a code is found. Keypressed property ?? Please need help ! :((

      T Offline
      T Offline
      Tim Kohler
      wrote on last edited by
      #2

      Are you talking about a winform or asp.net app? If it's winform, you should be able to subscribe to the keydown (or keyup) event. Look at the args to the event and then set the selected index in your grid to whatever row (and whatever column in the row you're talking about) matches the key. If it's asp.net, you could hook up a javascript function and try to perhaps set a background color on one of the rows. But that will be quite difficult as you will have to interogate the generated table's cell values (innertext i think) and then set a background color on the row with the matching value. Another way to go might be to put a text box up above the grid and a button beside it that says something like 'find'. Let them type a text fragment into the box and then use the button's event to search the grid contents.

      G 1 Reply Last reply
      0
      • T Tim Kohler

        Are you talking about a winform or asp.net app? If it's winform, you should be able to subscribe to the keydown (or keyup) event. Look at the args to the event and then set the selected index in your grid to whatever row (and whatever column in the row you're talking about) matches the key. If it's asp.net, you could hook up a javascript function and try to perhaps set a background color on one of the rows. But that will be quite difficult as you will have to interogate the generated table's cell values (innertext i think) and then set a background color on the row with the matching value. Another way to go might be to put a text box up above the grid and a button beside it that says something like 'find'. Let them type a text fragment into the box and then use the button's event to search the grid contents.

        G Offline
        G Offline
        Gammaza
        wrote on last edited by
        #3

        Yes im talking about a windows form. I did the textbox and button thing but i want as less buttons as possible. Im trying the keydown event ... but having some trouble with it. The datagrid wants to refresh and get the data from the dataset again but i just want it to scroll down to the letter, letters or word ...

        1 Reply Last reply
        0
        • G Gammaza

          Hi everyone.... Can anyone tell me if its possible to autosearch a datagrid if the user starts typing on it ? For example if the user starts typing in a Code field, the datagrid must go to the first location equal to the character pressed etc. until a code is found. Keypressed property ?? Please need help ! :((

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          Probably not exactly what you are looking for but I wrote an article which filters the DataGrid. You can find it here[^].

          G 1 Reply Last reply
          0
          • R Robert Rohde

            Probably not exactly what you are looking for but I wrote an article which filters the DataGrid. You can find it here[^].

            G Offline
            G Offline
            Gammaza
            wrote on last edited by
            #5

            Something like that , just without the testboxes and filter only by one field. Thanks anyway ;)

            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