Using Csharp .NET4.0 and ms visual studio 2010.
I have a really buggy problem that is to say the least bugging the hell out of me.
I have a datagridview that displays a league table of parts most sold. What the program does is allow the user to change the league positions around based on there own knowledge and judgement.
Once entering numbers in, the user can save there progress which updates a table on my MS SQL local server. But before the information is saved it runs a method that checks for any duplicated numbers in the column that has information being entered.
If it detects any duplicates it refuses to save, and informs the user with the part name displayed in another smaller datagridview. From here the user can then select the parts displayed and it will auto navigate and highlight the main datagridview for the user to make appropriate changes.
Now the Problem is the following, If a user enters a duplicate value, then clicks else where in the datagridview, then clicks save, the program runs correctly.
But if the user enters a duplicate value and goes straight to save, it bugs big time. Basically it saves the data that was there before the user entered data, also it does not show any duplicate values.
I believe this is because the cell that the user entered data in has not been updated.
I can provide some code if it will help. Just wandering if this is a common problem with a common fix?
Many Regards
CODE:
private void saveMyProgressToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result2 = MessageBox.Show("Do you wish to save you progress?",
"Important Question",
MessageBoxButtons.YesNo);
if (result2 == DialogResult.Yes)
{
CheckForDuplicate();
if (dupi == true)
{
CountMyGrid();
dupi = false;
}
else
{
Task t = new Task(() => SaveMyWorkI());
t.Start();
dupi = false;
}
}
}
The code above checks to see if it is ok to save or not based on the duplicate method boolean toggle.
public void CheckForDuplicate()
{
DataGridViewRowCollection coll = ParetoGrid.Rows;
DataGridViewRowCollection colls = ParetoGrid.Rows;
IList<String> listParts = new List<String>();
int count = 0;
foreach (DataGridViewRow item in coll)//379
{
foreach (DataGridViewRow items in colls)//143641
{
count++;
if ((items.Cells["NewPareto"].Value != null) && (items.Cells["NewPareto"].Value != DBNull.Value))
{
if ((items.Cells["NewPareto"].Value != DBNull.Value) && (items.Cells["NewPareto"].Value != null) && (items.Cells["NewPareto"].Value.Equals(item.Cells["NewPareto"].Value)))
{
if ((items.Cells["Part"].Value != DBNull.Value) && (items.Cells["Part"].Value != null) && !(items.Cells["Part"].Value.Equals(item.Cells["Part"].Value)))
{
listParts.Add(items.Cells["Part"].Value.ToString());
dupi = true;
}
}
}
}
}
MyErrorGrid.DataSource = listParts.Select(x => new { Part = x }).ToList();
}
if you excuse the constant checks for null types, this part cycles through detecting any duplicates.
If you require any more code just ask and ill be happy to provide.
Try to apply the
function to the DataGridView. If that does not work try
Note that you should apply this right before saving the information.