private void chkBoxChange(object sender, EventArgs e) { CheckBox chk = (CheckBox)sender; if (chk.Checked == true) { TextBox txtBx = new TextBox(); Rectangle rect = this.dgvItemVendor.GetCellDisplayRectangle(Convert.ToInt32(chk.Name.Split('#')[0]), -1, false); txtBx.Name = chk.Name.Split('#')[0] + "#-1"; txtBx.Size = new Size(rect.Width - 20, 10); rect.Offset(0, 0); txtBx.Location = rect.Location; txtBx.Multiline = true; txtBx.Height = 18; this.dgvItemVendor.Controls.Add(txtBx); txtBx.Focus(); txtBx.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtBx_txtKeyPress); } } private void txtBx_txtKeyPress(object sender, KeyPressEventArgs e) { cpattern = 'S'; dgvItemVendor.CurrentCell = null; TextBox txtGetText = (TextBox)sender; if (e.KeyChar == Convert.ToChar(Keys.Back)) { if (txtGetText.Text != string.Empty) { strSearchQuery = txtGetText.Text.Substring(0, txtGetText.Text.Length - 1); } } else { strSearchQuery = txtGetText.Text + e.KeyChar; } if (e.KeyChar == '') { if (Clipboard.ContainsText()) { strSearchQuery = Clipboard.GetText(); } } if (strSearchQuery.Length > 1) { if (strSearchQuery.StartsWith("*")) cpattern = 'E'; if (strSearchQuery.StartsWith("*") && strSearchQuery.EndsWith("*")) cpattern = 'C'; } strSearchQuery = strSearchQuery.Replace("*", string.Empty); //if (System.Text.RegularExpressions.Regex.IsMatch(dgvItemVendor.Rows[k].Cells[Convert.ToInt32(txtGetText.Name.Split('#')[0])].Value.ToString() // , strSearchQuery // , System.Text.RegularExpressions.RegexOptions.IgnoreCase)) for (int k = 0; k < dgvItemVendor.RowCount; k++) { switch (cpattern) { case 'E': dgvItemVendor.Rows[k].Visible = (dgvItemVendor.Rows[k].Cells[Convert.ToInt32(txtGetText.Name.Split('#')[0])].Value.ToString().EndsWith(strSearchQuery, true, null)) ? true : false; break; case 'C': dgvItemVendor.Rows[k].Visible = (dgvItemVendor.Rows[k].Cells[Convert.ToInt32(txtGetText.Name.Split('#')[0])].Value.ToString().ToUpper().Contains(strSearchQuery.ToUpper())) ? true : false; break; default: dgvItemVendor.Rows[k].Visible = (dgvItemVendor.Rows[k].Cells[Convert.ToInt32(txtGetText.Name.Split('#')[0])].Value.ToString().StartsWith(strSearchQuery, true, null)) ? true : false; break; } } } catch (Exception ex) { CustomException.ShowCustomException(ex); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)