private void TxtListDescription_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (string.IsNullOrEmpty(TxtListDescription.Text)) { if (GridList.Rows.Count <= 1) { MessageBox.Show("Description Cannot Left Blank !", "Mr Solution", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtListDescription.Focus(); } else { GridControlMode(false); } } else { if (SetTextBoxValueToGrid() == true) { if (GridList.CurrentRow.Index == (GridList.Rows.Count - 1)) { GridList.Rows.Add(); GridList.CurrentCell = GridList.Rows[GridList.Rows.Count - 1].Cells["Description"]; } else { GridList.CurrentCell = GridList.Rows[GridList.CurrentRow.Index + 1].Cells["Description"]; } GridControlMode(true); } else { if (this.ActiveControl != TxtListDescription) { SendKeys.Send("{Tab}"); } } } }
private void GridControlMode(bool mode) { if (Grid.CurrentRow != null) { int currRo = Grid.CurrentRow.Index; int colindex = 0; if (mode == true) { colindex = Grid.Columns["CompanyCode"].Index; TxtGridCompanyCode.Size = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Size; TxtGridCompanyCode.Location = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Location; colindex = Grid.Columns["CompanyName"].Index; TxtGridCompanyName.Size = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Size; TxtGridCompanyName.Location = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Location; colindex = Grid.Columns["SalesRateChange"].Index; TxtGridSalesRateChange.Size = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Size; TxtGridSalesRateChange.Location = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Location; colindex = Grid.Columns["SalesTermChange"].Index; TxtGridSalesTermChange.Size = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Size; TxtGridSalesTermChange.Location = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Location; colindex = Grid.Columns["PurchaseRateChange"].Index; TxtGridPurchaseRateChange.Size = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Size; TxtGridPurchaseRateChange.Location = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Location; colindex = Grid.Columns["PurchaseTermChange"].Index; TxtGridPurchaseTermChange.Size = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Size; TxtGridPurchaseTermChange.Location = this.Grid.GetCellDisplayRectangle(colindex, currRo, true).Location; } SetGridValueToTextBox(currRo); } TxtGridCompanyCode.Enabled = mode; TxtGridCompanyCode.Visible = mode; TxtGridCompanyName.Enabled = mode; TxtGridCompanyName.Visible = mode; TxtGridSalesRateChange.Enabled = mode; TxtGridSalesRateChange.Visible = mode; TxtGridSalesTermChange.Enabled = mode; TxtGridSalesTermChange.Visible = mode; TxtGridPurchaseRateChange.Enabled = mode; TxtGridPurchaseRateChange.Visible = mode; TxtGridPurchaseTermChange.Enabled = mode; TxtGridPurchaseTermChange.Visible = mode; if (mode == true) { BtnOk.Enabled = false; } else { BtnOk.Enabled = true; } if (mode == true) { TxtGridCompanyCode.Focus(); } }