How do I dynamically set up a DataGridTableStyle and DataGridTextBoxColumns when the number of columns from my datatable or dataview may change each time?

I want to eliminate Null from the cells. My research indicates I need to use DataGridTableStyle to accomplish this. But my columns may come and go depending on what data is available in my datatable or dataview. How do I dynamically do that when I seem to need a new DataGridTextBoxColumn for each column?
Who is Participating?
Hi IT_Steve,

Here's the easy way to do it without specifically setting up each DataFridTextBoxColumn:

     After you set the datasource of the datagrid, add the following code:

        Dim myGridTableStyle As DataGridTableStyle = New DataGridTableStyle
        myGridTableStyle.MappingName = DataGrid1.DataSource.TableName

        For Each dgtbc As DataGridTextBoxColumn In DataGrid1.TableStyles(0).GridColumnStyles
            dgtbc.NullText = ""
Bob LearnedCommented:
You can eliminate nulls at the source, depending on what type of datasource you are binding to.

IT_SteveAuthor Commented:
Amyhxu -

Thank you ...that was exactly what I needed. I like this easy solution.
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.