-
Jul 11th, 2020, 06:04 AM
#1
Thread Starter
Fanatic Member
Last edited by nader; Jul 11th, 2020 at 06:17 AM.
-
Jul 11th, 2020, 07:37 AM
#2
Re: The problem with name and size column of DGV
Just as you could not set properties of a control at design time if you did not add the control at design time, you cannot set properties of a column if you do not add that column at design time. Once you have added the grid, select it and open the Properties window, select the Columns property and click the (...) button to open the Edit Columns dialogue. There you can add a columns of the appropriate type and configure them just as you would a control. Be sure to set the DataPropertyName of each grid column, to specify what data source column they should bind to. If you don't, new columns will be added automatically when you bind. The DataPropertyName should be set to a String containing the name of the data source property/column, i.e. "Mate", "Knd1" and "Knd2" in your case.
-
Jul 13th, 2020, 03:30 AM
#3
Lively Member
Re: The problem with name and size column of DGV
Hello,@nader
Please try this code,To The problem with name and size column of DGV
You could set the width of the abbrev column to a fixed pixel width, then set the width of the description column to the width of the DataGridView, minus the sum of the widths of the other columns and some extra margin (if you want to prevent a horizontal scrollbar from appearing on the DataGridView):
Code:
dataGridView1.Columns[1].Width = 108; // or whatever width works well for abbrev
dataGridView1.Columns[2].Width =
dataGridView1.Width
- dataGridView1.Columns[0].Width
- dataGridView1.Columns[1].Width
- 72; // this is an extra "margin" number of pixels
If you wanted the description column to always take up the "remainder" of the width of the DataGridView, you could put something like the above code in a Resize event handler of the DataGridView.
I hope this information will be useful for you.
Thank you.
-
Jul 13th, 2020, 03:44 AM
#4
Re: The problem with name and size column of DGV
Originally Posted by Prahlad
Hello,@nader
Please try this code,To The problem with name and size column of DGV
You could set the width of the abbrev column to a fixed pixel width, then set the width of the description column to the width of the DataGridView, minus the sum of the widths of the other columns and some extra margin (if you want to prevent a horizontal scrollbar from appearing on the DataGridView):
Code:
dataGridView1.Columns[1].Width = 108; // or whatever width works well for abbrev
dataGridView1.Columns[2].Width =
dataGridView1.Width
- dataGridView1.Columns[0].Width
- dataGridView1.Columns[1].Width
- 72; // this is an extra "margin" number of pixels
If you wanted the description column to always take up the "remainder" of the width of the DataGridView, you could put something like the above code in a Resize event handler of the DataGridView.
I hope this information will be useful for you.
Thank you.
The question specifically asked how to set column properties at design time. Also, if you want the last column to fill the rest of the available space then you should set its AutoSizeMode to Fill.
-
Jul 13th, 2020, 08:44 AM
#5
Thread Starter
Fanatic Member
Re: [RESOLVED] The problem with name and size column of DGV
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|