Datagrids are a really neat way of displaying multiple records at the same time on a form. They look a bit like a table, with column headings (fields or data items) and rows (records from a textfile).
These videos show you all you need to know about creating a datagrid, displaying, adding and updating data from textfiles using a datagrid.
Creating a DataGrid
Alternatively, you could add a datagrid to your form and then use this code to create the columns in your datagrid:
Adding & Updating Data
Displaying / Retrieving Data
Checking the update works
Clearing a datagrid
Choosing a value in the datagrid, then displaying associated data in textboxes
There are two ways to create a datagrid, so there are also two ways to add columns to the grid:
As described earlier, the datagrid can be created in the code. To add an extra column, add 1 to the ColumnCount (change it to 6 in this example), then add a new line of code:
DataGridView1.Columns(5).Name = "Totals"
You can also create a datagrid by adding one to your form from the toolbox, then adding the columns, one at a time.
Name = what VB will refer to it as e.g. Totals
Header Text = what you want to see as your column heading e.g. Total (£)
When you want to create additional columns in your datagrid, just add your new column in the same way as you set up your datagrid. Click on the little triangle in the top right of the datagrid and choose Add Column..
Datagrid with additional field/column--->
Set up a variable (called TotalsTemp in this example). This will be used to accumulate the costs of the other items.
Here is the whole procedure, which will add up all your costs and output the total in the Totals column.
Note:
Note:
Note - this line of code will allow display of the datagrid only i.e. the data cannot be clicked on, or altered by the user.
Code to format a particular cell in a data grid based on rules