PC Review


Reply
Thread Tools Rate Thread

auto sizing data grid view

 
 
sajit
Guest
Posts: n/a
 
      26th Mar 2010
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?
 
Reply With Quote
 
 
 
 
Family Tree Mike
Guest
Posts: n/a
 
      26th Mar 2010
On 3/26/2010 7:34 AM, sajit wrote:
> 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.

--
Mike
 
Reply With Quote
 
Phill W.
Guest
Posts: n/a
 
      26th Mar 2010
On 26/03/2010 11:34, sajit wrote:

> 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.
 
Reply With Quote
 
sajit
Guest
Posts: n/a
 
      26th Mar 2010
On Mar 26, 4:46*pm, Family Tree Mike <FamilyTreeM...@ThisOldHouse.com>
wrote:
> On 3/26/2010 7:34 AM, sajit wrote:
>
> > 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.
>
> --
> 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.
 
Reply With Quote
 
sajit
Guest
Posts: n/a
 
      26th Mar 2010
On Mar 26, 5:11*pm, "Phill W." <p-.-a-.-w-a-r...@-o-p-e-n-.-a-c-.-u-k>
wrote:
> On 26/03/2010 11:34, sajit wrote:
>
> > 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.


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.
 
Reply With Quote
 
Family Tree Mike
Guest
Posts: n/a
 
      26th Mar 2010
On 3/26/2010 11:24 AM, sajit wrote:
> On Mar 26, 4:46 pm, Family Tree Mike<FamilyTreeM...@ThisOldHouse.com>
> wrote:
>> On 3/26/2010 7:34 AM, sajit wrote:
>>
>>> 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.
>>
>> --
>> 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.

--
Mike
 
Reply With Quote
 
Patrick A
Guest
Posts: n/a
 
      26th Mar 2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Grid View vimal.424@gmail.com Microsoft C# .NET 1 24th Jan 2008 05:37 PM
Grid View / Data Grid =?Utf-8?B?TWFyY28=?= Microsoft Access Forms 4 3rd May 2007 06:03 PM
how to bind Data to Grid view with custom data class. =?Utf-8?B?dmluZWV0YmF0dGE=?= Microsoft ADO .NET 0 16th Oct 2006 07:06 AM
Scrolling trough data in Data Grid View Merdex Microsoft Dot NET 1 17th Feb 2006 11:52 PM
auto-sizing width of table windows in query design view =?Utf-8?B?YW5kcmV3?= Microsoft Access Queries 1 11th Feb 2005 12:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:22 PM.