|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Setting DataGridView.Height to Goldilocks value?in it? Not too big, not too small. I looked for a property which I could set such that the Height would grow as I added rows. But found no such property. So I thought, OK, I can calculate the value, after populating the DataGridView, like this ... MasterSegs(cmsi).Height = (MasterSegs(cmsi).Rows.Item(0).Height * MasterSegs(cmsi).Rows.Count) _ + MasterSegs(cmsi).ColumnHeadersHeight (All rows are the same height and there is always at least one row.) But that creates extra space within the control but beyond the last row. In one case I was able to set exactly the right size by getting rid of the vertical scroll bar. But in another case getting rid of the vertical scroll bar made no difference - there is still unused space beyond the last row. I even tried subtracting 1 and even 2 from the Rows.Count but that didn't seem to make any difference. This is really annonying as I am trying to layout consecuitive DataGridViews in a Panel and I don't know how to specify the Y locations of the DataGridViews. My searches found that this problem comes up from time to time but I have not found a solution posted. Thanks, Bob Hi Bob,
Are you aware that there are no 80*25 rows monitors anymore. The way something is showed is completely depended from the setting form the user. My experience (but you can ignore that) is the more I do to make it look nice on my screen, the more it looks awfully on other screens Cor Show quoteHide quote "eBob.com" <eBob.***@totallybogus.com> wrote in message news:OaYnCy86JHA.3304@TK2MSFTNGP06.phx.gbl... > How do I set the Height of a DataGridView to just accomodate what I've put > in it? Not too big, not too small. > > I looked for a property which I could set such that the Height would grow > as I added rows. But found no such property. > > So I thought, OK, I can calculate the value, after populating the > DataGridView, like this ... > > MasterSegs(cmsi).Height = (MasterSegs(cmsi).Rows.Item(0).Height * > MasterSegs(cmsi).Rows.Count) _ > + MasterSegs(cmsi).ColumnHeadersHeight > > (All rows are the same height and there is always at least one row.) > > But that creates extra space within the control but beyond the last row. > In one case I was able to set exactly the right size by getting rid of the > vertical scroll bar. But in another case getting rid of the vertical > scroll bar made no difference - there is still unused space beyond the > last row. > > I even tried subtracting 1 and even 2 from the Rows.Count but that didn't > seem to make any difference. > > This is really annonying as I am trying to layout consecuitive > DataGridViews in a Panel and I don't know how to specify the Y locations > of the DataGridViews. > > My searches found that this problem comes up from time to time but I have > not found a solution posted. > > Thanks, Bob
Show quote
Hide quote
"eBob.com" <eBob.***@totallybogus.com> wrote in message I'm pretty sure you need to handle the datagridview yourself, as there is news:OaYnCy86JHA.3304@TK2MSFTNGP06.phx.gbl... > How do I set the Height of a DataGridView to just accomodate what I've put > in it? Not too big, not too small. > > I looked for a property which I could set such that the Height would grow > as I added rows. But found no such property. > > So I thought, OK, I can calculate the value, after populating the > DataGridView, like this ... > > MasterSegs(cmsi).Height = (MasterSegs(cmsi).Rows.Item(0).Height * > MasterSegs(cmsi).Rows.Count) _ > + MasterSegs(cmsi).ColumnHeadersHeight > > (All rows are the same height and there is always at least one row.) > likly no sizing mode to do what you want. You seem to only be changing the control height based on content, not the cell height. Given that, you will likely run out of real estate on the form at some time. > But that creates extra space within the control but beyond the last row. Are you calling your resize routine at startup? I don't see why this would > In one case I was able to set exactly the right size by getting rid of the > vertical scroll bar. But in another case getting rid of the vertical > scroll bar made no difference - there is still unused space beyond the > last row. be seen > I even tried subtracting 1 and even 2 from the Rows.Count but that didn't Try subtracting 2 pixels * the number of rows. It worked for me. My guess > seem to make any difference. is the height includes the borders, which are off by one because the cells don't repeat the border if one is next to it. You are not docking or anchoring the control, are you? > Don't dock or anchor the panel either.> This is really annonying as I am trying to layout consecuitive > DataGridViews in a Panel and I don't know how to specify the Y locations > of the DataGridViews. > The datagridview.Location is how you specify the location of the datagridview. In general though, I think using the scrollbars for a docked datagridview is what users expect. -- Mike
Enable/Disable windows update
vb.net app not finding application configuration file on Windows 2003 Server Standard Problem with Windows Server 2003 Standard R2 Not as 'explicit' as I thought --- What am I missing Formatting Text on a textbox Is this Normal? A question about a failing regular expression Error adding a data provider to a datagridview control limiting combobox.... Pass Variable At Design Time |
|||||||||||||||||||||||