DataGridView in windows form not showing results when autogeneratecolumns is set to false, when binding to a generic list.

Hi,

I am mainly an asp.net developer but recently I have been working on a small windows application and was struggling to get data to display on a DataGridView control when using AutogenerateColumns set to false.

If I set AutogenerateColumns to true it works perfectly, but why is it not working when I manually set the columns?

Is there something extra that you need to do when using set columns?

LVL 2
jazz__manAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Gyanendra SinghConnect With a Mentor ArchitectCommented:
azz__man:

you need to set column.DataPropertyName = "filedname"; property.. this is a key if you are using
AutoGenerateColumns  false
0
 
Gyanendra SinghArchitectCommented:
refer this example and compare  your your code... and put missing part in your code
http://msdn.microsoft.com/en-us/library/y0wfd4yz.aspx
0
 
jazz__manAuthor Commented:
BondinASP:
I used the designer to create the columns, whereas your example does everything in code. Is there a difference in using the designer?

I just don't understand why something as simple as creating your own column headers should make it not work. I have worked with Datagrids and Gridviews extensively in asp.net but cannot seem to get things working in a DataGridView.

The DataGridView expands as if it has brought back data but all the fields are blank.

Its weird, because if I take the columns out and set AutoGenerateColumns back to true everything works.
0
 
jazz__manAuthor Commented:
Thanks, that was the bit that was missing.
0
 
Gyanendra SinghArchitectCommented:
your welcome
0
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.