Click here to Skip to main content
12,446,146 members (81,374 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# DataGridView
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)
                {
                    try
                    {
                        GridUtitlity.strFind = tsTxtSearch.Text.Trim();
                        frmReviewSummary.lstFindRef.DataSource = null;
                        rowIndex = 0;
                        roles.Clear();
                        
                        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.Show(frmReviewSummary.dockPanel1);
                        frmReviewSummary.contFindref.DockState = DockState.DockBottom;
                        frmReviewSummary.contFindref.Focus();
                    }
                    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?

Thanks,
Viprat
Posted 16-Sep-12 19:29pm
VIPR@T2.8K
Updated 16-Sep-12 19:31pm
v2
Rate this: bad
 
good
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:
try
{
    GridUtitlity.strFind = tsTxtSearch.Text.Trim();
    MessageBox.Show("Hello");
    /*
     *  Your code goes here
     */
}

--Amit
  Permalink  
Comments
VIPR@T 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
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,

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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2016
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