Searching programatically in GridView

5 posts, 0 answers
  1. Attila
    Attila avatar
    4 posts
    Member since:
    Oct 2016

    Posted 07 Nov Link to this post

    Hello there,

    I'm trying to implement a basic barcode scanner into my winforms application with radGridView. I'd like to search the GridView using this barcode scanner, so I have to fill the searchbox programatically. This is successful: I scan a code, it appears in the box. I have to use the Form's KeyPreview property set to TRUE and the Form's KeyPress event (because the scan ends as soon as the scanner send a NewLine character). Here's the code:

    private string qrCode=string.Empty;

    private void Form1_KeyPress(object sender, KeyPressEventArgs e)
    {
        qrCode+=e.KeyChar;
        if (e.KeyChar == (char) Keys.Return)
        {
            StartSearch();
        }
    }

    private void StartSearch()
    {
        GridViewSearchRowInfo searchRow = this.grdMyGridView.MasterView.TableSearchRow;
        searchRow.SearchProgressChanged += mySearchResult;
        searchRow.Search(qrCode);
        qrCode=string.Empty;
    }

    private void mySearchResult(object sender, SearchProgressChangedEventArgs e)
    {
        Console.WriteLine("Results: " + e.Cells.Count);
    }

     

    My problem is, that I always get 0 results. The searchbox has the search string, this is no problem. If I type this string manually into this box, I get results perfectly. I want my GridView to show the results of scanned strings. Is this possible?

    Thanks again for your help!

    Attila

  2. Attila
    Attila avatar
    4 posts
    Member since:
    Oct 2016

    Posted 07 Nov in reply to Attila Link to this post

    If I'm not subscribing to the SearchProgressChanged event and add 2 lines before the searchRow.Search method:

    searchRow.HighlightResults = true;
    searchRow.AutomaticallySelectFirstResult = true;

    I get the result. But I don't think this could be the normal way to do it. 

    In this case I have 1 more question: how can I clear the searchbox text programmatically?

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 07 Nov Link to this post

    Hello Attila,

    Thank you for writing.  

    I would like to note that we already have a feature request for a barcode generator. You can track its progress, subscribe for status changes and add your comments on the following link - https://feedback.telerik.com/Project/154/Feedback/Details/111885-add-new-control-barcode-generator-control

    As to the search behavior, I would recommend you to have a look at the following help article which explains how the search functionality works and how to use the SearchProgressChanged event: http://docs.telerik.com/devtools/winforms/gridview/rows/search-row

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  5. Attila
    Attila avatar
    4 posts
    Member since:
    Oct 2016

    Posted 07 Nov in reply to Dess Link to this post

    Dear Dess,

    Thanks for your fast reply. I read this search-row article before I sent you my first post. I still don't know how to clear the search box programmatically. Is there any way to do that?

    Thanks

    Attila

  6. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 07 Nov Link to this post

    Hello Attila, 

    Thank you for writing back. 

    In order to clear the search criteria, you can call the Search method passing null as a parameter:
    this.radGridView1.MasterView.TableSearchRow.Search(null);

    I hope this information helps. If you have any additional questions, please let me know. 

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready