sammi taylor

sammi taylor

  • NA
  • 19
  • 0

Show messagebox if no data returned in datagridview

Apr 12 2015 5:31 PM
I have a SearchForm where user enters data in textboxes, btnSearchClick displays data in a datagridivew if there is data in the database. This works fine.
If no data is returned, I need message box to say no search returned, enter a new record.
 
My messagebox pops up for both when there are records returned AND when there are no records returned.
  
private void btnSearch_Click(object sender, EventArgs e)  
{  
     //this binds all textboxes to the dgv. This works fine
     BindData();  

     dgvSearch.DataSource = bindingSource1;  
 
     //Need help  here. Only display messagebox if there are no records returned.
     //It pops up each time, even when there are records returned. 
     
     if (dgvSearch.Rows.Count < -1)  
     {  
           dgvSearch.ReadOnly = true;  
     }  
     else  
     {  
           MessageBox.Show("No search results returned, clear your search and enter new case");  
      } }
 

Answers (3)