Khalil Khalaf
Khalil Khalaf

Reputation: 9407

How to set datagridview's rows/columns width to the datagridview's width?

Excuse me, a quick question:

I am using this routine to display a list of strings into a datagridview:

List<string> MyDataSource = MyList.Select(x => Path.GetFileNameWithoutExtension(x)).ToList();

AllVideosGrid.DataSource = MyDataSource.ConvertAll(x => new { Value = x });

Designer generated code:

// MyGrid
// 
this.AllVideosGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.AllVideosGrid.Location = new System.Drawing.Point(33, 185);
this.AllVideosGrid.Name = "AllVideosGrid";
this.AllVideosGrid.RowTemplate.Height = 24;
this.AllVideosGrid.Size = new System.Drawing.Size(319, 498);
this.AllVideosGrid.TabIndex = 32;

And it gets displayed like this:

enter image description here

I would like rows to be resized to the datagridview size that I set initially in my designer. How can I do that?

Upvotes: 0

Views: 36

Answers (1)

Mario Righi
Mario Righi

Reputation: 62

for horizontal strecth use this:

this.AllVideosGrid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

For vertical I think that's not possible, eventually you can set the height for each row

Upvotes: 1

Related Questions