Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problems with foreach on grid sorted by user
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Problems with foreach on grid sorted by user
Environment versions
Environment:
C# 3.0
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01478511
Message ID:
01478511
Views:
100
I have a DataGridView bound to a table with an unbound column that the user can check or uncheck to indicate records to be stamped with a posting date. If the user doesn't change the sort order (by clicking the column heading), everything works fine. If the sort order is changed, it misses rows.
Here is my code:
            foreach (DataGridViewRow Row in grdTimeRecordHistory.Rows)
            {
                if (Convert.ToInt32(Row.Cells[this.Select2PostColumn.Index].Value) == 1)
                {
                    //Post
                    Row.Cells[this.PostedTRHColumn.Index].Value = selectedPostDate;
                }
            }
this.Select2PostColumn is the column name of the column they use to check the rows to be included.

I can't just cycle through the table because the Select2Post column is not a column in the table. I prefer not to add this column to the database table simply for this purpose. I tried capturing the current DataGridView.SortOrder and DataGridView.SortColumn but haven't found a way to set them to nothing because those properties are ReadOnly.
Do I need to switch to using a DataView for this?
Thanks.

I figured this out. The sort was changing the row index, apparently, since the sort the user chose was the column being changed. I changed the code to make the updates to a separate biz object and save the row after each change. At the end of the foreach loop, I repopulate the table. The only downside is that I lose the information about the selected rows. We can probably live with that.
Linda Harmes
HiBit Technologies, Inc.
Reply
Map
View

Click here to load this message in the networking platform