private void ansGridView5_KeyPress(object sender, KeyPressEventArgs e) { if (char.IsLetter(e.KeyChar) || char.IsNumber(e.KeyChar) || e.KeyChar == ' ' || Convert.ToInt32(e.KeyChar) == 13) { } else { return; } if (ansGridView5.CurrentCell.OwningColumn.Name == "pack" || ansGridView5.CurrentCell.OwningColumn.Name == "itemname") { String ActiveCell = ""; if (ansGridView5.CurrentCell.OwningColumn.Name == "pack") { ActiveCell = "Packing"; } else if (ansGridView5.CurrentCell.OwningColumn.Name == "itemname") { ActiveCell = "Desc"; } DataTable dtDesc = new DataTable(); if (Master.DescriptionInfo.Select("Description<>''", "Description, PACKING").Length == 0) { return; } else { dtDesc = Master.DescriptionInfo.Select("Description<>'' and Status='Enable'", "Description, PACKING").CopyToDataTable(); } DataTable dtPack = new DataTable();; if (ActiveCell == "Packing" && ansGridView5.CurrentCell.OwningRow.Cells["itemname"].Value != null && ansGridView5.CurrentCell.OwningRow.Cells["itemname"].Value.ToString() != "") { dtDesc = dtDesc.Select("description='" + ansGridView5.CurrentCell.OwningRow.Cells["itemname"].Value.ToString() + "'").CopyToDataTable(); } else if (ActiveCell == "Desc" && ansGridView5.CurrentCell.OwningRow.Cells["pack"].Value != null && ansGridView5.CurrentCell.OwningRow.Cells["pack"].Value.ToString() != "") { dtDesc = dtDesc.Select("Packing='" + ansGridView5.CurrentCell.OwningRow.Cells["pack"].Value.ToString() + "'").CopyToDataTable(); } if (ActiveCell == "Packing") { dtPack = dtDesc.DefaultView.ToTable(true, "Packing"); } else { dtPack = dtDesc.DefaultView.ToTable(true, "description"); } DataRow[] SKU = dtDesc.DefaultView.ToTable(true, "Skucode").Select("Skucode<>''"); DataRow[] ShortCode = dtDesc.DefaultView.ToTable(true, "ShortCode").Select("ShortCode<>''"); DataTable dtPS; DataTable dtPSS; if (SKU.Length > 0) { DataTable dtSKU = SKU.CopyToDataTable(); dtPS = dtPack.AsEnumerable() .Union(dtSKU.AsEnumerable()).CopyToDataTable(); } else { dtPS = dtPack.Copy(); } if (ShortCode.Length > 0) { DataTable dtShortCode = ShortCode.CopyToDataTable(); dtPSS = dtPS.AsEnumerable() .Union(dtShortCode.AsEnumerable()).CopyToDataTable(); } else { dtPSS = dtPS.Copy(); } String packing = "", Desc = ""; if (ActiveCell == "Packing") { packing = SelectCombo.CallHelp(this, dtPSS, e.KeyChar.ToString(), 0); if (packing == "") { return; } dtDesc = dtDesc.Select("Packing='" + packing + "' or Skucode='" + packing + "' or ShortCode='" + packing + "'").CopyToDataTable(); } else { Desc = SelectCombo.CallHelp(this, dtPSS, e.KeyChar.ToString(), 0); if (Desc == "") { return; } dtDesc = dtDesc.Select("description='" + Desc + "' or Skucode='" + Desc + "' or ShortCode='" + Desc + "'").CopyToDataTable(); } if (dtDesc.Rows.Count == 1) { if (ansGridView5.CurrentCell.OwningRow.Cells["itemname"].Value == null || ansGridView5.CurrentCell.OwningRow.Cells["itemname"].Value.ToString() == "") { ansGridView5.CurrentCell.OwningRow.Cells["itemname"].Value = dtDesc.Rows[0]["description"]; } ansGridView5.CurrentCell.OwningRow.Cells["Pack"].Value = dtDesc.Rows[0]["Packing"]; ansGridView5.CurrentCell.OwningRow.Cells["Quantity"].Value = 0; this.Activate(); } else if (dtDesc.Rows.Count > 1) { if (ActiveCell == "Packing") { ansGridView5.CurrentCell.OwningRow.Cells["pack"].Value = dtDesc.Rows[0]["Packing"]; ansGridView5.CurrentCell.OwningRow.Cells["itemname"].Value = ""; } else { ansGridView5.CurrentCell.OwningRow.Cells["itemname"].Value = dtDesc.Rows[0]["description"]; ansGridView5.CurrentCell.OwningRow.Cells["pack"].Value = ""; } ansGridView5.CurrentCell.OwningRow.Cells["Quantity"].Value = 0; this.Activate(); if (ActiveCell == "Packing") { ansGridView5.CurrentCell = ansGridView5["itemname", ansGridView5.CurrentCell.RowIndex]; } else { ansGridView5.CurrentCell = ansGridView5["pack", ansGridView5.CurrentCell.RowIndex]; } } } }