Also Read
DataGridView in Windows Form
The DataGridView control displays data in a customizable table. The DataGridView control allows you to display and edit tabular data from a variety of data sources. Cells, rows, columns, and borders in the DataGridView class can be customized using properties such as DefaultCellStyle, CellBorderStyle, GridColor, and ColumnHeadersDefaultCellStyle.
A DataGridView control can be used to display data with or without an underlying data source. You can create data-filled columns and rows and add them directly to the DataGridView using the Rows and Columns properties without specifying a data source.
In today's article we will learn how we can add data at runtime in the DataGridView Control. In the last article, we learned how to add data with the help of Data Source like Database in DataGridView without writing code, if you want to see that article, you can click here.
STEP 1. First, create the windows form project in Visual Studio.
STEP 2. When you create the project, you will have a form like this. Now drag and drop the DataGridView control from the toolbox something like you can see in the image.
STEP 3. Now add the columns in the DataGridView as explained in the image. You have a property of DataGridView of AutoSizeColumnMode, change this property from None to Fill. The advantage of this is that your columns are adjusted according to the size of the DataGridView.
STEP 5. Now you have to double click on the 'ADD' button and write this code.
STEP 6. Now you have to double click on the 'CLEAR' button and write this code.
I am also giving you the download link of the entire file here, if you need it, you can download it.
if any issue comes up, you can comment to us or you can watch a video on this topic on our YouTube Channel.
0 Comments