Grid View - Errors and Not Saving Last Row.....
- From: Andy <Andy@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 2 Jan 2007 05:36:00 -0800
Hello All:
I am having some issues with the use of the GridView in my C# 2.0
application. I have some checks to make sure that the cell values are valid,
but mostly just to make sure there is a value in them, and not empty.
However: this is causing much confusion because the last column never saves
(it DOES save if I click out of the row into another row, but this doesn't
seem like a very viable solution) the value when I hit the "Save" button on
my toolstrip that is connected to the GridView.
Below is my code. I am hoping someone notices what I am doing wrong and why
the last value (column) in my dataGrid never saves (except once you click
outside the cell). Thanks for any help you guys might be able to provide.
//***********************************************************// Name:
Products_Load
// Desc:
//***********************************************************private void
Products_Load(object sender, EventArgs e)
{
this.tBoardsTableAdapter.Fill(this.boardsDataSet.tBoards);
this.tProductsTableAdapter.Fill(this.productsDataSet.tProducts);
dgvProducts.CellEndEdit += new DataGridViewCellEventHandler
(dgvProducts_CellEndEdit);
dgvProducts.CellValidating += new DataGridViewCellValidatingEventHandler
(dgvProducts_CellValidating);
}
//***********************************************************// Name:
dgvProducts_CellValidating
// Desc:
//***********************************************************private void
dgvProducts_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
//-------------------------------------------------------------------------------------
// Validate the LastName entry by disallowing empty strings
//-------------------------------------------------------------------------------------
if (dgvProducts.Columns[e.ColumnIndex].Name == "Description")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dgvProducts.Rows[e.RowIndex].ErrorText = "Description Cannot be
empty";
e.Cancel = true;
}
}
if (dgvProducts.Columns[e.ColumnIndex].Name == "DonatedBy")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dgvProducts.Rows[e.RowIndex].ErrorText = "Donated By Cannot be
empty";
e.Cancel = true;
}
}
if (dgvProducts.Columns[e.ColumnIndex].Name == "Retail")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dgvProducts.Rows[e.RowIndex].ErrorText = "Retail Cannot be empty";
e.Cancel = true;
}
}
}
//***********************************************************// Name:
dgvProducts_CellEndEdit
// Desc:
//***********************************************************private void
dgvProducts_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
//-------------------------------------------------------------------------------------
// Clear the row error in case the user presses ESC
//-------------------------------------------------------------------------------------
dgvProducts.Rows[e.RowIndex].ErrorText = String.Empty;
}
//***********************************************************// Name:
tsbAddProduct_Click
// Desc:
//***********************************************************private void
tsbAddProduct_Click(object sender, EventArgs e)
{
dgvProducts.CurrentCell = dgvProducts.Rows[dgvProducts.Rows.Count -
1].Cells
["DonatedBy"];
dgvProducts.BeginEdit(true);
}
//***********************************************************// Name:
saveToolStripButton_Click
// Desc:
//***********************************************************private void
saveToolStripButton_Click(object sender, EventArgs e)
{
tProductsBindingSource.EndEdit();
tProductsTableAdapter.Update(productsDataSet.tProducts);
}
.
- Prev by Date: Re: How can I add '+' or '-' before float value using float.ToString() ?
- Next by Date: Re: Web Interface for a c# Console Application
- Previous by thread: Re: Multiple Client Simulation
- Next by thread: Re: Is there a way to query Security Event Log with Filter in C#?
- Index(es):