Home All Groups Group Topic Archive Search About

Help with Datagridviews

Author
9 Jun 2006 9:05 AM
Mike Fellows
Hi,

Im populating a datagridview with a dataset using

datagridview.datasource = dataset.tables(0)

and this works fine in most cases, except when my dataset has multiple lines
of text in a single row

for example if i had an address stored as below:

    street
    address2
    town
    county
    postcode
    country

the above address would just show the intial line, my question is then how
do I get the datagridview to autosize on row height to show all the
available information

Thanks in advance

Mike Fellows

Author
9 Jun 2006 6:22 PM
Ken Tucker [MVP]
Hi,

       Here is a quick example.  Set the datagridviews autosizerowsmode to
allcells


        Dim strConn As String = _
           "Server = .\SQLEXPRESS;Database = NorthWind; Integrated Security
= SSPI;"
        Dim conn As New SqlConnection(strConn)
        Dim da As New SqlDataAdapter("Select LastName, Notes from
Employees", conn)

        da.Fill(dt)

        DataGridView1.DataSource = dt
        With DataGridView1.Columns("Notes")
            .Width = 150
            .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
            .DefaultCellStyle.WrapMode = DataGridViewTriState.True
        End With

Ken
------------------------------------

Show quoteHide quote
"Mike Fellows" wrote:

> Hi,
>
> Im populating a datagridview with a dataset using
>
> datagridview.datasource = dataset.tables(0)
>
> and this works fine in most cases, except when my dataset has multiple lines
> of text in a single row
>
> for example if i had an address stored as below:
>
>     street
>     address2
>     town
>     county
>     postcode
>     country
>
> the above address would just show the intial line, my question is then how
> do I get the datagridview to autosize on row height to show all the
> available information
>
> Thanks in advance
>
> Mike Fellows
>
>
>
Author
28 Jun 2006 10:25 AM
Mike Fellows
Thanks Ken

Worked a treat

Cheers

Mike Fellows


Show quoteHide quote
"Ken Tucker [MVP]" <KenTucker***@discussions.microsoft.com> wrote in message
news:65D790E1-2A02-4028-B4B8-4CEF47FEA514@microsoft.com...
> Hi,
>
>       Here is a quick example.  Set the datagridviews autosizerowsmode to
> allcells
>
>
>        Dim strConn As String = _
>           "Server = .\SQLEXPRESS;Database = NorthWind; Integrated Security
> = SSPI;"
>        Dim conn As New SqlConnection(strConn)
>        Dim da As New SqlDataAdapter("Select LastName, Notes from
> Employees", conn)
>
>        da.Fill(dt)
>
>        DataGridView1.DataSource = dt
>        With DataGridView1.Columns("Notes")
>            .Width = 150
>            .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
>            .DefaultCellStyle.WrapMode = DataGridViewTriState.True
>        End With
>
> Ken
> ------------------------------------
>
> "Mike Fellows" wrote:
>
>> Hi,
>>
>> Im populating a datagridview with a dataset using
>>
>> datagridview.datasource = dataset.tables(0)
>>
>> and this works fine in most cases, except when my dataset has multiple
>> lines
>> of text in a single row
>>
>> for example if i had an address stored as below:
>>
>>     street
>>     address2
>>     town
>>     county
>>     postcode
>>     country
>>
>> the above address would just show the intial line, my question is then
>> how
>> do I get the datagridview to autosize on row height to show all the
>> available information
>>
>> Thanks in advance
>>
>> Mike Fellows
>>
>>
>>