Cell/Column Index for DataGridView versus DataTable?

For a DataGridView AND DataTable...does the column index always start with zero?
Who is Participating?
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.

Kyle AbrahamsSenior .Net DeveloperCommented:
Yes it does . . . BUT note that they don't necessarily match (EG: sorting).

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
BlakeMcKennaAuthor Commented:
I thought so...just wanted to be sure!

Thanks Kyle
BlakeMcKennaAuthor Commented:

I did notice one thing in my DGV. I have several cells that are Invisible and noticed that it affects the column index.

For example, my dgv has 10 columns (0 - 9 index). Column 0 - 3 are Invisible. The initial value in column 11 is 73.6. After the dgv is setup (making columns 0 - 3 invisible), the value 73.6 is not in column 7.

Is there a way to maintain values and column indexes even though certain dgv columns are invisible?
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

BlakeMcKennaAuthor Commented:
The reason I ask is because my CellFormatting Even references the "e.ColumnIndex". This is where the column indexes are different.
Kyle AbrahamsSenior .Net DeveloperCommented:
There's something else going on there . . .   you can set the visible property on the indexed column itself:

Do you have auto generate columns set to false?
BlakeMcKennaAuthor Commented:
AutoGenerateColumns isn't set, which I assume defaults to False...
BlakeMcKennaAuthor Commented:
I actually execute a procedure that defines the DGV.DataPropertyName (which is the same as the DataTable Column Names) and HeaderText...
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.