This is a migrated thread and some comments may be shown as answers.

Searching programatically in GridView

4 Answers 791 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Attila
Top achievements
Rank 2
Attila asked on 07 Nov 2016, 10:24 AM

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

4 Answers, 1 is accepted

Sort by
0
Attila
Top achievements
Rank 2
answered on 07 Nov 2016, 10:46 AM

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?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Nov 2016, 11:28 AM
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.
0
Attila
Top achievements
Rank 2
answered on 07 Nov 2016, 12:12 PM

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

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Nov 2016, 01:13 PM
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.
Tags
GridView
Asked by
Attila
Top achievements
Rank 2
Answers by
Attila
Top achievements
Rank 2
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or