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?
 
lazyberezovskyConnect With a Mentor Commented:
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
 
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
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
 
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
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.