Contents of cells not updating in DataGridView (Windows.Forms: VS2008)

After my data is populated in the DataGrid on my windows form, I am trying to format 2 columns (first column to have commas; second column to be currency) via code.  

The problem is the grid will not reflect the changes unless I take the mouse and manually click on a column in the grid.

How can I refresh the data programmatically to reflect my formats?
With objDataGrid
            Dim cellNumFormat As DataGridViewCell = New DataGridViewTextBoxCell
            Dim cellCurrFormat As DataGridViewCell = New DataGridViewTextBoxCell
	    Dim ds As New Data.DataSet
            .DataSource = ds
            .DataMember = "Table"

	    '***sort the data...
            .Sort(.Columns(0), System.ComponentModel.ListSortDirection.Ascending)

	    '****make a column invisible...
            .Columns(0).Visible = False   'Do not show "Line#" column.

	    '*** apply the "currency" and "number" formats to 2 columns...
            cellNumFormat.Style.Format = "n"
            .Columns(6).CellTemplate = cellNumFormat
            cellCurrFormat.Style.Format = "c"
            .Columns(7).CellTemplate = cellCurrFormat

	    '***Try to refresh the grid...
	    .Refresh()
            Application.DoEvents()
            .AutoResizeColumns()
End With

Open in new window

pic-bfore.bmp
pic-after.bmp
Try2BeBetterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

UnifiedISCommented:
Try objDataGrid.invalidate
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Try2BeBetterAuthor Commented:
Thank you so much.  Almost there...

I placed in the code and it still does not format the first time.  But if I process another number for the grid to process, the formatting appears in the columns.

Any ideas?
0
UnifiedISCommented:
Can I assume that you are unable to define the columns during design time?
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Try2BeBetterAuthor Commented:
Exactly.  The column information is populated when I populate the dataset from our mainframe.  The data grid sets up the columns when I assign it to the "datasource" property.

Why do you ask?  What were you thinking?
0
UnifiedISCommented:
If you could set it at design time, this would all be unnecessary.  
When you are referencing columns by their index, it would seem like you have a static data structure and would be able to do this at design time.  Otherwise, how do you know that columns(6) should be number format?


0
Try2BeBetterAuthor Commented:
The problem was I was trying to configure the DataGridView control during the form's .Show() method.  I was not allowing the DataGridView control to fully render at the form's opening.

The method worked.  But also needed is the following:  Form.Refresh(); Application.DoEvents(); DataGridView.RefreshEdit()
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.