Doug DeBug

Is it possible to change the DataGridView to display n columns on the first row, n columns on the second row, etc. I have a DataGridView bound to a row but not enough screen real estate to display all the fields without scrolling. The Details view from the DataSource offers the ability to arrange the fields but doesn't offer the functionality of the DataGridView.

Thanks!

DeBug



Re: Windows Forms Data Controls and Databinding How to wrap a row in the DataGridView?

Gavin Jin - MSFT

Hi,please check this code

Imports System.Data

Imports System.Data.SqlClient

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim conn As New SqlConnection("Server=(Local);" & _

"DataBase=Northwind; Integrated Security=SSPI")

Dim sqlstr As String = "SELECT FirstName,LastName,BirthDate,HireDate FROM Employees"

Dim command As New SqlCommand(sqlstr, conn)

Dim dt As New DataTable

dt.Columns.Add("c1", GetType(System.String))

dt.Columns.Add("c2", GetType(System.String))

conn.Open()

Dim reader As SqlDataReader = command.ExecuteReader()

While reader.Read()

Dim line, line1 As String

line = reader.GetString(0).ToString()

line1 = reader.GetString(1).ToString()

dt.Rows.Add(line, line1)

Dim line2, line3 As String

line = reader.Getdate(0).ToString()

line1 = reader.Getdate(1).ToString()

dt.Rows.Add(line2, line3)

End While

conn.Close()

Me.DataGridView1.DataSource = dt

End Sub

End Class

My computer doesnot have VS,so I cannot debug it,maybe the "Gerdate" is not correct,you can change it when you debug.But this method is right.

Hope it helps.

Hope it helps.

Regards