Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
C#
public bool  IsCellOrRowHeader(int x, int y)
       {
           try
           {
               DataGridViewHitTestType dgt = dgv.HitTest(x, y).Type;
               return (dgt == DataGridViewHitTestType.Cell ||
                          dgt == DataGridViewHitTestType.RowHeader);
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message, "Limit Viewer");
               writeErrorlog("Limit Viewer ( IsCellOrRowHeader)", ex.Message, ex.StackTrace);
               return;//An object of a type convertible to 'bool' is required
           }
       }
Posted
Updated 31-May-10 1:09am
v2

Your code should be as following.

public bool IsCellOrRowHeader(int x, int y)
        {
            try
            {
                DataGridViewHitTestType dgt = dgv.HitTest(x, y).Type;
                return (dgt == DataGridViewHitTestType.Cell ||
                           dgt == DataGridViewHitTestType.RowHeader);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Limit Viewer");
                writeErrorlog("Limit Viewer ( IsCellOrRowHeader)", ex.Message, ex.StackTrace);
                return false;//
            }
        }




Your method return type is bool so all the code path should return a boolean value. In this case your catch block is returning void. So change the return; to return false;
 
Share this answer
 
v2
ankitparekh56 wrote:
public bool IsCellOrRowHeader(int x, int y)


Your method signature states that the return type is a Boolean value.



ankitparekh56 wrote:
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Limit Viewer");
writeErrorlog("Limit Viewer ( IsCellOrRowHeader)", ex.Message, ex.StackTrace);
return;//An object of a type convertible to 'bool' is required
// set as return = false;
}


You are not returning a boolean value in case of exception. Just set it to true or false. Since the signature states, it has to be boolean, you have to set the return type as boolean even though if there is an exception.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900