Microsoft Knowledge Base Email Alertz

KBAlertz.com: Explains that you receive an incorrect count of the modified rows in a DataGrid control when you modify a column and then scroll the column out of the visible area.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 835405 - Last Review: May 21, 2007 - Revision: 1.4

FIX: The DataGrid control reports an incorrect row count when a modified column is hidden by scrolling when you are using the .NET Framework 1.1

On This Page

SYMPTOMS

When you scroll the column of a DataGrid control out of the visible area after you modify the column and then you access the count of the rows that are modified, you receive an incorrect row count.

CAUSE

This problem occurs because the Leave event of the DataGrid control typically causes the EndCurrentEdit method to update the data source. However, when you modify a column and then you scroll that column out of view, the Leave event does not cause the EndCurrentEdit method to be called. Therefore, the changes that are made to the DataGrid control are not updated in the data source.

RESOLUTION

To resolve this problem, obtain the latest service pack for the Microsoft .NET Framework 1.1. To download the latest service pack visit the following Microsoft Developer Network (MSDN) Web site:
http://www.microsoft.com/downloads/details.aspx?FamilyId=A8F5654F-088E-40B2-BBDB-A83353618B38 (http://www.microsoft.com/downloads/details.aspx?FamilyId=A8F5654F-088E-40B2-BBDB-A83353618B38)

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section. This problem was first corrected in Microsoft .NET Framework 1.1 Service Pack 1.

MORE INFORMATION

Steps to reproduce the behavior

Create a Windows application

  1. Create a Windows application that is named MyApp by using Microsoft Visual Basic .NET 2003. By default, a form that is named Form1 and a file that is named Form1.vb are created.

    Note If you use Microsoft Visual C# .NET 2003, a file that is named Form1.cs is created.
  2. Add a DataGrid control to Form1.
  3. Add two Button controls to Form1. By default, the Button1 Button control and the Button2 Button control are created.
  4. On the View menu, click Properties Window.
  5. In the Properties window of the Button1 Button control, set the Text property to Apply.
  6. In the Properties window of the Button2 Button control, set the Text property to Load.
  7. In the Properties window of the DataGrid1 DataGrid control, set the Size property to 200, 150.

Add code to the form

  1. In Solution Explorer, right-click Form1.vb, and then click View Code.
  2. In the Code view of the Form1.vb file, add the following code to the declarations section of the Form1 class:

    Visual Basic .NET code
    Private dataSet1 As System.Data.DataSet
    Private TestTable As System.Data.DataTable
    Private dataColumn1 As System.Data.DataColumn
    Private dataColumn2 As System.Data.DataColumn
    Private dataColumn3 As System.Data.DataColumn
    Private dataColumn4 As System.Data.DataColumn
    Private dataColumn5 As System.Data.DataColumn
    Private dataColumn6 As System.Data.DataColumn
    Private dataColumn7 As System.Data.DataColumn
    Private dataColumn8 As System.Data.DataColumn
    Visual C# .NET code
    private System.Data.DataSet dataSet1;
    private System.Data.DataTable TestTable;
    private System.Data.DataColumn dataColumn1;
    private System.Data.DataColumn dataColumn2;
    private System.Data.DataColumn dataColumn3;
    private System.Data.DataColumn dataColumn4;
    private System.Data.DataColumn dataColumn5;
    private System.Data.DataColumn dataColumn6;
    private System.Data.DataColumn dataColumn7;
    private System.Data.DataColumn dataColumn8;
  3. In Design view, double-click the Form1 form, and then add the following code to the Form1_Load procedure:

    Visual Basic .NET code
    Me.dataSet1 = New System.Data.DataSet
    Me.TestTable = New System.Data.DataTable
    Me.dataSet1.DataSetName = "NewDataSet"
    Me.dataSet1.Locale = New System.Globalization.CultureInfo("en-US")
    'Add new columns to the data table.
    Me.dataColumn1 = New System.Data.DataColumn
    Me.dataColumn2 = New System.Data.DataColumn
    Me.dataColumn3 = New System.Data.DataColumn
    Me.dataColumn4 = New System.Data.DataColumn
    Me.dataColumn5 = New System.Data.DataColumn
    Me.dataColumn6 = New System.Data.DataColumn
    Me.dataColumn7 = New System.Data.DataColumn
    Me.dataColumn8 = New System.Data.DataColumn
    Me.dataSet1.Tables.AddRange(New System.Data.DataTable() {Me.TestTable})
    Me.TestTable.Columns.AddRange(New System.Data.DataColumn() {Me.dataColumn1, _
    Me.dataColumn2, Me.dataColumn3, Me.dataColumn4, Me.dataColumn5, Me.dataColumn6, _
    Me.dataColumn7, Me.dataColumn8})
    Me.TestTable.TableName = "TestTable"
    'Assign names to the columns of the data table.
    Me.dataColumn1.ColumnName = "ID"
    Me.dataColumn1.DataType = System.Type.GetType("System.Int32")
    Me.dataColumn2.ColumnName = "Column2"
    Me.dataColumn3.ColumnName = "Column3"
    Me.dataColumn4.ColumnName = "Column4"
    Me.dataColumn5.ColumnName = "Column5"
    Me.dataColumn6.ColumnName = "Column6"
    Me.dataColumn7.ColumnName = "Column7"
    Me.dataColumn8.ColumnName = "Column8"
    'Add rows to the data table.
    Dim values() As Object = {}
    Me.TestTable.Rows.Add(New Object() {1, "One", ""})
    Me.TestTable.Rows.Add(New Object() {2, "Two", ""})
    Me.TestTable.Rows.Add(New Object() {3, "Three", ""})
    Me.TestTable.Rows.Add(New Object() {4, "Four", ""})
    Me.TestTable.Rows.Add(New Object() {5, "Five", ""})
    Me.TestTable.AcceptChanges()
    
    Visual C# .NET code
    this.dataSet1 = new System.Data.DataSet();
    this.TestTable = new System.Data.DataTable();
    this.dataSet1.DataSetName = "NewDataSet";
    this.dataSet1.Locale = new System.Globalization.CultureInfo("en-US");
    //Add new columns to the data table.
    this.dataColumn1 = new System.Data.DataColumn();
    this.dataColumn2 = new System.Data.DataColumn();
    this.dataColumn3 = new System.Data.DataColumn();
    this.dataColumn4 = new System.Data.DataColumn();
    this.dataColumn5 = new System.Data.DataColumn();
    this.dataColumn6 = new System.Data.DataColumn();
    this.dataColumn7 = new System.Data.DataColumn();
    this.dataColumn8 = new System.Data.DataColumn();	
    this.dataSet1.Tables.AddRange(new System.Data.DataTable[] {this.TestTable});
    this.TestTable.Columns.AddRange(new System.Data.DataColumn[]{  
                                                                   this.dataColumn1,
                                                                   this.dataColumn2,
                                                                   this.dataColumn3,
                                                                   this.dataColumn4,
                                                                   this.dataColumn5,
                                                                   this.dataColumn6,
                                                                   this.dataColumn7,
                                                                   this.dataColumn8
                                                                 });
    this.TestTable.TableName = "TestTable";
    //Assign names to the columns of the data table.
    this.dataColumn1.ColumnName = "ID";
    this.dataColumn1.DataType = typeof(int);
    this.dataColumn2.ColumnName = "Column2";
    this.dataColumn3.ColumnName = "Column3";
    this.dataColumn4.ColumnName = "Column4";
    this.dataColumn5.ColumnName = "Column5";
    this.dataColumn6.ColumnName = "Column6"; 
    this.dataColumn7.ColumnName = "Column7"; 
    this.dataColumn8.ColumnName = "Column8";
    //Add rows to the data table.
    this.TestTable.Rows.Add(new object[]{1, "One", null});
    this.TestTable.Rows.Add(new object[]{2, "Two", null});
    this.TestTable.Rows.Add(new object[]{3, "Three", null});
    this.TestTable.Rows.Add(new object[]{4, "Four", null});
    this.TestTable.Rows.Add(new object[]{5, "Five", null});
    this.TestTable.AcceptChanges();
  4. In Design view of the Form1 form, double-click the Button1 Button control, and then add the following code to the Button1_Click procedure:

    Visual Basic .NET code
    Dim sourceDataView As New DataView((CType(Me.DataGrid1.DataSource, DataView).Table), _
    "", "", DataViewRowState.ModifiedCurrent)
    'Displays the count of the rows that are modified.
    MessageBox.Show(sourceDataView.Count.ToString())
    If (sourceDataView.Count <> 0) Then
        sourceDataView.Table.AcceptChanges()
    End If
    Visual C# .NET code
    DataView sourceDataView = new DataView(((DataView)this.dataGrid1.DataSource).Table, "", 
    "", DataViewRowState.ModifiedCurrent);
    //Displays the count of the rows that are modified.
    MessageBox.Show(sourceDataView.Count.ToString());
    if(sourceDataView.Count != 0)
    {
       sourceDataView.Table.AcceptChanges();
    }
  5. In Design view of the Form1 form, double-click the Button2 Button control, and then add the following code to the Button2_Click procedure:

    Visual Basic .NET code
    Dim dview As New DataView(Me.dataSet1.Tables("TestTable"))
    'Displays the data of the data table in the DataGrid control.
    Display(dview, "")
    Visual C# .NET code
    //Displays the data of the data table in the DataGrid control.
    this.Display(new DataView(this.dataSet1.Tables["TestTable"]),null);
    
  6. Add the following code after the Button2_Click procedure:

    Visual Basic .NET code
    Public Sub Display(ByVal dataSource As Object, ByVal dataMember As String)
        'Sets the data source of the DataGrid control.
        Me.DataGrid1.DataSource = dataSource
        Me.DataGrid1.DataMember = dataMember
    End Sub
    Visual C# .NET code
    public void Display(object dataSource, string dataMember)
    {
       //Sets the data source of the DataGrid control.
       this.dataGrid1.DataSource = dataSource;
       this.dataGrid1.DataMember = dataMember;
    }

Build the application

  1. On the Build menu, click Build Solution.
  2. On the Debug menu, click Start.
  3. On the Form1 form, click Load to load the data to the DataGrid control.
  4. Modify the value in the second column of any row in the DataGrid control.
  5. Without moving the row pointer from the second column of the DataGrid control, drag the horizontal scroll bar to the right by using the mouse pointer until the second column moves out of the visible area.
  6. Click Apply to display the count of the modified rows. Notice that the count is 0.
  7. Move the horizontal scroll bar back to the original position, and then click Apply again. Notice that the count is 1.

REFERENCES

For more information, visit the following MSDN Web sites:
DataView Class
http://msdn2.microsoft.com/en-us/library/system.data.dataview(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/system.data.dataview(vs.71).aspx)

DataGrid Control (Windows Forms)
http://msdn2.microsoft.com/en-us/library/aa983595(VS.71).aspx (http://msdn2.microsoft.com/en-us/library/aa983595(VS.71).aspx)
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
824684  (http://kbalertz.com/Feedback.aspx?kbNumber=824684/ ) Description of the standard terminology that is used to describe Microsoft software updates

APPLIES TO
  • Microsoft .NET Framework 1.1
Keywords: 
kbhotfixserver kbqfe kbnetframe110sp1fix kbnetframe110presp1fix kbforms kbcontrol kbdataview kbqfe kbfix kbbug KB835405
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please