Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2004

Tip: Looking for answers? Try searching our database.

view a single row in a datagrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel Dupont - 23 Jul 2004 10:58 GMT
Hi,
I'd like to show a row in a datagrid like this :

id_firm     1
name_firm     IBM
address_firm    NewYork DC
contact_firm     Mr Jones

Any idea (I'm getting crazy !)
regards,
D.
Gary Vidal - 23 Jul 2004 16:26 GMT
' I suggest you try to create a secondary datatable that transposes rows to
columns and columns to rows and then fill the values in by iterating .

'Pass the function the table to transpose as well as the primary key column
name i.e. InvoiceNumber

call the program like this:

Dim transdt as DataTable

transdt = TransposeDataTable(sometable,"id_firm")

datagrid1.datasource= transdt

Private Function TransposeDataTable(Byval CurrentTable as DataTable,Byval
PrimaryColumnName as String) as DataTable

Dim dt As New DataTable

Dim rows As Integer = 0

'add a column for the table values

Dim dcolvalue As New DataColumn("ColumnName")

With dcolvalue

.DataType = GetType(String)

.MaxLength = 255

End With

dt.Columns.Add(dcolvalue)

'loop through each row and create a column

For Each row As DataRow In CurrentTable.Rows

Dim dcol As New DataColumn(row(PrimaryColumnName).ToString) 'or add the
columnName as PrimaryKey

dt.Columns.Add(dcol)

rows += 1

Next

'iterate all the columns and create rows

For Each col As DataColumn In CurrentTable.Columns

Dim ColRow As DataRow

ColRow = dt.NewRow

ColRow.Item(0) = col.ColumnName

dt.Rows.Add(ColRow)

Next

'Now populate the information by iterating the rows over the columns

For i As Integer = 0 To CurrentTable.Rows.Count - 1

   For k As Integer = 0 To CurrentTable.Columns.Count - 1

       dt.Rows(k)(i + 1) = CurrentTable.Rows(i).Item(k)

   Next

Next

return dt

End Sub

> Hi,
> I'd like to show a row in a datagrid like this :
[quoted text clipped - 7 lines]
> regards,
> D.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.