1

我有两个文本框;

  1. 公司名称
  2. 顾客姓名

但是当我搜索FIrmBAsed信息时,我会在DataGridView1FromDataTAble1但是当我立即取消FirmName内容时,我会去搜索CUstome Name我从哪里获得行DATABLE1但无法显示在DataGridView1......而不是看到......我可以知道原因......

代码:

private void txtCustomerName_TextChanged(object sender, EventArgs e)
{
    if (txtCustomerName.Text == "")
    {
        dgvSearchData.Visible = false;
    }
    else
    {
        dgvSearchData.Visible = true;
        dgvSearchData.Location = new Point(txtCustomerName.Location.X, (txtCustomerName.Location.Y + txtCustomerName.Height));

        query = "Select CustomerName,FirmName, Address, City from CustomerMaster WHERE CustomerName LIKE '" + txtCustomerName.Text + "%' ";
        dtCustomer.Clear();
        dtCustomer = objDBConnection.fSelect(query);
        **dgvSearchData.DataSource = dtCustomer;**

        if (dgvSearchData.Rows.Count > 0) dgvSearchData.Rows[0].Selected = false;
        if (dgvSearchData.Rows.Count == 1) dgvSearchData.Rows[0].Selected = true;

        if (dgvSearchData.Rows.Count > 0)
            dgvSearchData.Height = (dgvSearchData.Rows.Count) * 23;

        if (dgvSearchData.Height >= new frmRetailBill().Size.Height)
            dgvSearchData.Height = new frmRetailBill().Size.Height - 20;

        for (int i = 1; i < dgvSearchData.Columns.Count; i++)
            dgvSearchData.Columns[i].Visible = false;
    }
}
 public void fillCusotmerData()
    {
        for (int i = 1; i < dgvSearchData.Columns.Count; i++)
            dgvSearchData.Columns[i].Visible = true;

        txtCustomerName.Text = dgvSearchData.SelectedRows[0].Cells["CustomerName"].Value.ToString();
        txtFirmName.Text = dgvSearchData.SelectedRows[0].Cells["FirmName"].Value.ToString();
        txtAddress.Text = dgvSearchData.SelectedRows[0].Cells["Address"].Value.ToString() + " " + dgvSearchData.SelectedRows[0].Cells["City"].Value.ToString();
        dgvSearchData.Visible = false;
        txtPartNumber.Focus();
    }
4

0 回答 0