Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / September 2006

Tip: Looking for answers? Try searching our database.

DataGridView clearing row error text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chuck P - 21 Sep 2006 19:52 GMT
I have a DataGridView where the user can make changes.
When he goes to quit he can either save or discard the changes.

I don't know if this is the best way to do it but I wrote

(this.BindingSource.DataSource as DataSet).RejectChanges();

object tempDataSource =dataGridView1.DataSource;
dataGridView1.DataSource = null;
dataGridView1.DataSource = tempDataSource;

for (int i = 0; i < dataGridView1.Rows.Count; i++)
          dataGridView1.Rows[i].ErrorText = "";

dataGridView1.Refresh();

The original values are back in the grid but the error text/icon
remains.

p.s. I know that if their is an error in the dataset that the error
automatically gets put in the  dataGridView1.Rows[i].ErrorText and
that trying to clear it doesn't work.  You have to clear it from the
datarowview.  So maybe RejectChanges is not clearing the error text in
the dataset?
Jeffrey Tan[MSFT] - 22 Sep 2006 08:42 GMT
Hi Chuck ,

Yes, based on the RejectChanges method logic, it will only roll back the
data changes to the data, it will not reset the ErrorText on row or cells.

To clear the error icon of the DataGridView, we may clear all the ErrorText
in the datasource, then the error icon will disappear. This is because the
.Net winform databinding will update your changes in datasource into the UI
DataGridViewRow.ErrorText property. My testing code snippet is listed below:

DataTable dt = null;
private void Form1_Load(object sender, EventArgs e)
{
   dt = new DataTable();
   dt.Columns.Add("column1", typeof(int));
   dt.Columns.Add("column2", typeof(string));
   for (int i = 0; i < 5; i++)
   {
       DataRow dr = dt.NewRow();
       dr["column1"] = i;
       dr["column2"] = "item" + i.ToString();
       dt.Rows.Add(dr);
   }
   dt.AcceptChanges();
   this.dataGridView1.DataSource = dt;
}

private void button1_Click(object sender, EventArgs e)
{
   this.dt.Rows[1].RowError = "abc";
}

private void button2_Click(object sender, EventArgs e)
{
   dt.RejectChanges();
   for (int i = 0; i < dt.Rows.Count; i++)
   {
       this.dt.Rows[i].RowError = "";
   }

   dataGridView1.Refresh();
}

This code snippet works well on my side. Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.