Cell/Column Index for DataGridView versus DataTable?

Posted on 2014-11-26
Last Modified: 2014-11-26
For a DataGridView AND DataTable...does the column index always start with zero?
Question by:BlakeMcKenna
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
LVL 40

Accepted Solution

Kyle Abrahams earned 500 total points
ID: 40467168
Yes it does . . . BUT note that they don't necessarily match (EG: sorting).

Author Closing Comment

ID: 40467191
I thought so...just wanted to be sure!

Thanks Kyle

Author Comment

ID: 40467203

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?
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Author Comment

ID: 40467206
The reason I ask is because my CellFormatting Even references the "e.ColumnIndex". This is where the column indexes are different.
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40467316
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?

Author Comment

ID: 40467381
AutoGenerateColumns isn't set, which I assume defaults to False...

Author Comment

ID: 40467385
I actually execute a procedure that defines the DGV.DataPropertyName (which is the same as the DataTable Column Names) and HeaderText...

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
No Data for DropDown List 2 32 and creating a class 5 31
get combo value in class 5 24
Need help with another query 10 39
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question