private void btnSearch_Click(object sender, EventArgs e) { if (tbCode.Text.Length < 4 & btnSearch.Visible) { searchResult = new FrmSearchResult(tbNames.Text, SearchBy.Name); } else { searchResult = new FrmSearchResult(tbCode.Text, SearchBy.Code); } if (searchResult.ShowDialog() == DialogResult.Yes) { frmAdd = new FrmAdd(searchResult.SelectedCode, searchResult.SelectedName, searchResult.SelectedPriceDC, searchResult.SelectedPricePC, searchResult.SelectedDiscont, searchResult.SelectedPeriodText, searchResult.selectedPeriod, searchResult.selectedYear); frmAdd.ShowDialog(); } dgvMain.DataSource = SkladBase.SearchProdByName(""); }
private void tbNames_TextChanged(object sender, EventArgs e) { if (tbNames.Text.Length > 0 || tbCode.Text.Length >= 4) { btnSearch.Enabled = true; } else { btnSearch.Enabled = false; } DataTable res = SkladBase.SearchProdByName(tbNames.Text); dgvMain.DataSource = res; //заполняем грид if (res.Rows.Count == 0) // если после поиска введенного кода выборка пуста, очищаем грид Details { DataTable dt = dgvDetails.DataSource as DataTable; if (dt != null) { dt.Clear(); } } }