当搜索结果为零时,我在我的软件中写了一个搜索功能。它没有给我任何弹出窗口或任何消息。如何处理这种情况我的代码如下。
我需要弹出任何消息,一旦它显示我的表中没有数据。
`private void cncInfoBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.cncInfoBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.cncDataSet1);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'cncDataSet1.CncInfo' table. You can move, or remove it, as needed.
this.cncInfoTableAdapter.Fill(this.cncDataSet1.CncInfo);
timer1.Start();
}
private void button1_Click(object sender, EventArgs e)
{
this.cncInfoBindingSource.AddNew();
}
private void button2_Click(object sender, EventArgs e)
{
this.Validate();
this.cncInfoBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.cncDataSet1);
}
private void button3_Click(object sender, EventArgs e)
{
this.cncInfoBindingSource.RemoveCurrent();
}
int count = 0;
private void timer1_Tick(object sender, EventArgs e)
{
count = cncInfoBindingSource.Count;
label_status.Text = "Records Found: " + count.ToString();
if (count < 2)
{
Next_btn.Visible = false;
Previous_btn.Visible = false;
}
else if (count <= 0)
{
MessageBox.Show("No records found ");
}
else
{
Next_btn.Visible = true;
Previous_btn.Visible = true;
}
}
private void Next_btn_Click(object sender, EventArgs e)
{
cncInfoBindingSource.MoveNext();
}
private void Previous_btn_Click(object sender, EventArgs e)
{
cncInfoBindingSource.MovePrevious();
}
private void button4_Click(object sender, EventArgs e)
{
this.cncInfoTableAdapter.SearchFileName(this.cncDataSet1.CncInfo, textBox1.Text);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
this.cncInfoTableAdapter.SearchFileName(this.cncDataSet1.CncInfo, textBox1.Text);
}
}
}
`
答案 0 :(得分:1)
在计时器上显示消息框非常难看。
然而,对于你要求帮助的问题:
你的代码是:if(count&lt; 2){/ 隐藏按钮 /} else if(count&lt; = 0){/ show message /} < / p>
永远不会显示消息框,因为0&lt; 2,代码只是隐藏了按钮。
答案 1 :(得分:0)
尝试:
if(cncInfoTableAdapter.GetData().Rows.Count < 1) MessageBox.Show("whatever");