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?
IT_SteveAsked:
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.

Bob LearnedCommented:
You can eliminate nulls at the source, depending on what type of datasource you are binding to.

Bob
amyhxuCommented:
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
        DataGrid1.TableStyles.Clear()
        DataGrid1.TableStyles.Add(myGridTableStyle)

        For Each dgtbc As DataGridTextBoxColumn In DataGrid1.TableStyles(0).GridColumnStyles
            dgtbc.NullText = ""
        Next

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
IT_SteveAuthor Commented:
Amyhxu -

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

From novice to tech pro — start learning today.