auto sizing data grid view

S

sajit

hi folks,
i am bit new to vb.net. My issue is, I have placed a datagridview
control on my win form. I am loading data into it as per user
selection from combo box. but issue is only few records are visible on
form, to view other record i have to manually click on vertical scroll
bars. Is there any way to fit the datagridview to show all records
without using scroll bars?
 
F

Family Tree Mike

hi folks,
i am bit new to vb.net. My issue is, I have placed a datagridview
control on my win form. I am loading data into it as per user
selection from combo box. but issue is only few records are visible on
form, to view other record i have to manually click on vertical scroll
bars. Is there any way to fit the datagridview to show all records
without using scroll bars?

Yes, you can adjust the size of the control on the change of the
combobox, but I recommend against that. It is very unusual in any
application for a control to grow/shrink based on a change of a value.
The recommended way to handle this would be setting the initial size of
the control to a reasonable proportional size for the form, and
anchoring the control to four sides. This way, the user can expand or
shrink the form, and the control will grow/shrink with it.
 
P

Phill W.

issue is only few records are visible on form, to view other record
I have to manually click on vertical scroll bars.
Is there any way to fit the datagridview to show all records
without using scroll bars?

To have the DataGridView (or any other Control for that matter) resize
along with your Form, experiment with the Anchor property.

If the DataGridView is inside another container (e.g. a Panel), try
setting the Dock property to "Fill".

You may still need the scroll bars - that just depends on how much data
you put into it.

HTH,
Phill W.
 
S

sajit

Yes, you can adjust the size of the control on the change of the
combobox, but I recommend against that.  It is very unusual in any
application for a control to grow/shrink based on a change of a value.
The recommended way to handle this would be setting the initial size of
the control to a reasonable proportional size for the form, and
anchoring the control to four sides.  This way, the user can expand or
shrink the form, and the control will grow/shrink with it.

hi mike I think u r getting me wrong. I am filling datagridview at run
time. The size can grow or shrink depending on the item selected from
combo box. The problem is datagridview is showing records on the size
I defined at design time, other records are only viewed by clicking on
scroll bars. Is there any property or event I can use to resize
datagridview dynamically.
 
S

sajit

To have the DataGridView (or any other Control for that matter) resize
along with your Form, experiment with the Anchor property.

If the DataGridView is inside another container (e.g. a Panel), try
setting the Dock property to "Fill".

You may still need the scroll bars - that just depends on how much data
you put into it.

HTH,
    Phill  W.

hi Phill I think u r getting me wrong. I am filling datagridview at
run time. The size can grow or shrink depending on the item selected
from combo box. The problem is datagridview is showing records on the
size I defined at design time, other records are only viewed by
clicking on scroll bars. Is there any property or event I can use to
resize datagridview dynamically.
 
F

Family Tree Mike

hi mike I think u r getting me wrong. I am filling datagridview at run
time. The size can grow or shrink depending on the item selected from
combo box. The problem is datagridview is showing records on the size
I defined at design time, other records are only viewed by clicking on
scroll bars. Is there any property or event I can use to resize
datagridview dynamically.

Actually, you are now describing what I thought I understood, and
described as a bad thing. My understanding is that you have a form, and
based on a combo box selection, a datagridview is filled with many rows.
You want the datagridview to be large enough so there is no scrollbar.
It is a bad thing to have a control grow like this for the user.
Users expect scrollbars on these things when there are many rows.

If you insist on changing the size of the datagridview, you would need
to use the RowHeight property to multiply by the number of rows to
change the control height.
 
P

Patrick A

Sajit,

Be careful though - based on my experience doing something similar
with programmatically creating buttons on a panel, if you make the
datagrid large enough to accomodate all of the rows, and there are
more rows in the datagrid than will appear on the form, you may not
get any scroll bars at all, and then users have no way of getting at
the records that flow off the form...

FWIW

Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top