Click here to Skip to main content
11,412,182 members (58,408 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# DataGridView WinForm
Hello Friends,

I am getting one strange problem.
I have code like below.

private void tsTxtSearch_KeyPress(object sender, KeyPressEventArgs e)
            if (tsTxtSearch.Text != "")
                if (e.KeyChar == (char)Keys.Enter)
                        GridUtitlity.strFind = tsTxtSearch.Text.Trim();
                        frmReviewSummary.lstFindRef.DataSource = null;
                        rowIndex = 0;
                        List<int[]> listSMS = GetSearchArrayFromGrid(frmReviewSummary.dgSMS);
                        frmReviewSummary.dgSMS.DataSource = GridUtitlity.dtSMS;
                        frmReviewSummary.dgSMS.CellPainting += new DataGridViewCellPaintingEventHandler(dgSMS_CellPainting);
                        frmReviewSummary.lstFindRef.DataSource = roles;
                        frmReviewSummary.lstFindRef.DisplayMember = "Name";
                        frmReviewSummary.lstFindRef.ValueMember = "Id";
                        frmReviewSummary.contFindref.DockState = DockState.DockBottom;
                    catch (Exception ex)

This code is working in fine when i check using debugger. But when i remove my debug point its not working. i am not getting what happening. If i keep debug point then its working fine and if i remove the debug point its not working.
Can any one please help in this?

Posted 16-Sep-12 20:29pm
Edited 16-Sep-12 20:31pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Right way of asking question.
Add a MessageBox inside try block and check without putting a break-point. Whether the debugger is coming inside or not. Clean and rebuild your solution.
Try this:
    GridUtitlity.strFind = tsTxtSearch.Text.Trim();
     *  Your code goes here

VIPR@T at 17-Sep-12 1:41am
I had check using MessageBox is well. This Event is going to call. But not giving me desired out put. If u put debug point and check then its working. I had tried with key_down event is well. But the same problem.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


Possiblity of this behavior is,

You are calling some long running Thread function that is not yet completed and You are trying to get the value updated by that thread. In such scenario debug will work as there is delay between next line execution. To check such issue, you need to add some Thread.Sleep.

I found such a place in your code. Display the message of listSMS count(As in Solution1 by _Amy). If it gives the correct result then look for your other code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 348
1 Sascha Lefévre 175
2 ProgramFOX 130
3 Maciej Los 110
4 Sergey Alexandrovich Kryukov 105
0 Sergey Alexandrovich Kryukov 8,980
1 OriginalGriff 7,263
2 Maciej Los 3,500
3 Abhinav S 3,248
4 Peter Leow 3,059

Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100