How do I control the column type and format of the data in a Grid?

How do I control the column type and format of the data in a Grid?  I want to do the following:

1) Add a column that contains a check box, and determine if the row is selected based on the column with the check box.
2) Control the width of the column.
3) Control the format of the data that is displayed.
4) Have the column headings remain fixed and NOT scroll when I scroll the data.
5) Set the text for the Column headings.  By default, they are set based on the bound data.
LVL 1
HLRosenbergerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lazyberezovskyCommented:
1) Is it WinForms or ASP.NET?
2) What framework do you use?
3) Is it standard or third-party control?
0
HLRosenbergerAuthor Commented:
I'm coding in VB.NET.   Framework?  Visual Studio, .NET.   Standard.

I figured out part of it.  Ya click on the little arrow at the top right, and GridView tasks screen appears.  I can set the column heading, the font, the format of the data.

I still want to 1) Add a column that contains a check box, and determine if the row is selected based on the column with the check box.
2) Control the width of the column.
0
lazyberezovskyCommented:
You should set from code (to prevent generating columns)
dataGridView1.AutoGenerateColumns = False
Then go to designer. Select "Columns" property of grid.
Add DataGridViewCheckBoxColumn for first column.
Add all other columns. Specify:
1) ColumnType – type of column (use DataGridViewTextBoxColumn or any other type you wish).
2) DataPropertyName – name of property that will be bound to column.
3) Width – column width (also see AutoSizeMode and MinWidth)
4) DefaultCellStyle – here you can add data format.

0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

lazyberezovskyCommented:
Ah there is one tricky moment - when adding first DataGridViewCheckBoxColumn, you should specify TrueValue and FalseValue properties (set true and false correspondingly).

Then you can get selected rows so:
For Each row As DataGridViewRow In dataGridView1.Rows
   Dim cell As DataGridViewCheckBoxCell = DirectCast(row.Cells(0), DataGridViewCheckBoxCell)
   If cell.Value = cell.TrueValue Then
      'do something with that row
   End If
Next

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HLRosenbergerAuthor Commented:
Thanks so much.

One more question.  if I'm creating a DataTable, unbound, in code, how do I then associated that table with the grid, so that I can display the data in the grid?
0
lazyberezovskyCommented:
If you want bind DataTable to grid, just set table as grid's DataSource.
0
HLRosenbergerAuthor Commented:
thanks again!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.