Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with a DataGridView 1

Status
Not open for further replies.

CraigBest

Programmer
Aug 1, 2001
545
US
Hi folks

Working on a new project in VB.NET 2008, and trying to display data from a Table in a DataGridView control.

I don't want to display everything in the table, just some records where a specific field (Selected) has a value of "X". I was having trouble with that so I added a DataView and set the filter to Selected = "X". That got me the data I wanted, but it's proving a problem to show updates in the grid when new records are added programmatically.

A second problem I have is in trying to set up the columns. I am trying to pre-define the column headers and field names to the values of the fields in the dataview being passed but they don't get filled, the data gets added on with extra columns after the preset columns are displays (empty). These are unbound fields because the recordset, table and DataView is not predefined, it's done in a query string.

Would love some help trying to figure out how to make this work.

CraigHartz
 
Set DataGridView.AutoGenerateColumns to False
Make sure you set the .DataPropertyName property for each column you create in your DataGridView.

And finally, when you're saying you're not showing updates to the grid, how are you adding these records? To the database? If so, are you filling your DataTable again?
 
Sweet, thanks - that did it. I didn't know about the DataPropertyName. I thought the Name property took care od that - now I know better.

And refilling the data table - Yea I think you're right, I wasn't thinking about that. I'll try to do that and see what happens.

CraigHartz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top