VB.net grid-reorder columns

SchoolTeacher54
SchoolTeacher54 used Ask the Experts™
on
Hello,

I have a vb.net grid bound to a table. There many ways that I have designed in to search the data in the table. All is well until I want to reorder the columns. Specifically I want to place the term searched 'search' field in the first column. The column name below for [state] works great. The column name for [Last Name] does not work; instead throwing an exception indicating the data field is not found. I am sure that the field name is correct as I have copied it out of the grid properties into the code. I tried other single word fields which all work fine. Fields such as [First Name] and [Last Name] don't work at all with the same exception taken.

I surmise that I need to wrap the "two-word" field names differently. Ideas?

 Does not work: Master_ContactsDataGridView.Columns("Last Name").DisplayIndex = 1
 Works: Master_ContactsDataGridView.Columns("State").DisplayIndex = 2
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014
Commented:
I found it helpful to set a breakpoint in my code just before the trouble and then use the Immediate window to determine exactly what .NET is expecting. For example:

?Master_ContactsDataGridView.Column(0).Name

Replace the 0 with your column indexes to see what you should be using for that name.

Author

Commented:
VERY helpful. I'll report back. Thank you!

Author

Commented:
That was the advice that I needed. I am a non-current developer that spent the better part of 20 years developing in VB6 and before. The things we (I) forget...

Thank you Scott! I wrote it down.

Author

Commented:
Thank you! Scott. Good advice and so timely.
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
You're welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial