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?
 
UnifiedISCommented:
Try objDataGrid.invalidate
0
 
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.