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!

DataGridView - losing formatting of unbound rows

Status
Not open for further replies.

CraigBest

Programmer
Aug 1, 2001
545
US
Hoping someone can help...

I'm using a DataGridView to display information from an unbound table. The first time I load the grid it uses my formatting settings I created at design time, which is great, looks perfect. But when I refresh the DataTable the grid is bound to as a Data Source, I lose all my formatting.

How do I get the control to re-use my formatting settings? On other third-party grid controls I've used you had the ability to save your formatting as a template file, and at run time use those settings to define the formatting for the grid. I don't see anything like that here - I do see a DGV.RowTemplate property / method but in reading the description I don't know if that will help.

Worst comes to worst I know I can manually define the formatting in code and read it in every time I load the grid, but I do not relish the thought of having to copy and edit all the individual statements. Is there a way to 'dump' the contents of the columns collection of a grid control in readable control.attribute format so I can easily re-use it?

I've already checked out the Designer and it wasn't of nay help.

Thanks

Craig

CraigHartz
 
Using Vb.Net 2010

I'm having same problem all of a sudden, but with a bound set. dgDetail.DataSource = Nothing seems to cause the complete wipe of all settings now. Doesn't happen in any of my previous forms.

--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
 
Hey SoonerJoe

I think I figured out a solution after banging my head on this all day yesterday - don't set the datasource property to nothing. Instead, just before you issue a new Fill command, do a Dataset.Datatable.Clear() call. then fill the datatable as you would have. This worked out for me.

Hope it helps!

Craig

CraigHartz
 
Found it.... forgot about a little property that must be set at run-time:
Code:
dgStages.AutoGenerateColumns = False

--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top