IMO, the best (and most efficient) way to do this is to create an extra column at the end so that it can βeatβ (or β tackle,β) a space that is not occupied by other columns. The way to do this is to set the AutoSizeMode property to .
Here is a sample code:
DataGridView grid = new DataGridView(); DataTable data = new DataTable(); //add columns, rows, etc. to DataTable data data.Columns.Add("This is the first column."); data.Rows.Add(data.NewRow()); //etc. //Add EXTRA column: data.Columns.Add(""); //blank header //Save changes data.AcceptChanges(); //Set datasource grid.DataSource = data;
Now you have a grid with an additional empty column. We must set the column to the desired properties:
data.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; //Sets AutoSizeMode to fill, as explained above, for 2nd column
In addition, as najameddine explained, you can set the following properties:
ReadOnly = true;
SortMode = NotSortable;
Essentially, you create an empty column that takes up empty space.
PS I just noticed that suraidhamarai has a very similar code example, but mine is in C #, however the concept remains the same.
Maxim zaslavsky
source share