VB.Net DataGridView Expand and Contract row groups 2020 12 29

  Рет қаралды 1,609

Peter Keats

Peter Keats

Күн бұрын

Пікірлер: 4
@arief_pujianto_
@arief_pujianto_ 2 жыл бұрын
Can u share to me the source code sir? I've been trying for a month, but failed.
@oakbank1953
@oakbank1953 2 жыл бұрын
Imports System.Data Imports System.Data.SqlClient Public Class frmUSAStates Private Sub frmUSAStates_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' www.sqlusa.com/bestpractices/dynamicsql/ ScreenWidth = Screen.PrimaryScreen.Bounds.Width ScreenHeight = Screen.PrimaryScreen.Bounds.Height Me.CenterToScreen() Dim adapter As New SqlDataAdapter Dim ds As New DataSet Dim CountOfRows As Integer = 0 sSQL = "select " sSQL = sSQL & "StateName, Abbreviation, Capital, LargestCity, Established, Population, " sSQL = sSQL & "Area_sqmiles, Area_sqkm, LandArea_sqmiles, LandArea_sqkm, WaterArea_sqmiles, WaterArea_sqkm, Representatives " sSQL = sSQL + "From tblUSAStates " sSQL = sSQL + "order by Abbreviation" OpenDB(sSQL) cmd.CommandText = sSQL cmd.ExecuteNonQuery() cmd = New SqlCommand(sSQL, cnn) adapter.SelectCommand = cmd adapter.Fill(ds) dgy = -1 dgx = -1 dgvTreeView.Rows.Clear() dgvTreeView.RowCount = 9999 For Each row As DataRow In ds.Tables(0).Rows If CountOfRows = 0 Then dgvTreeView.ColumnCount = row.Table.Columns.Count + 1 'dgvTreeView.Rows(dgx).Cells(0).Value = "+" For xx = 0 To row.Table.Columns.Count - 1 dgvTreeView.Columns(xx + 1).HeaderText = row.Table.Columns(xx).Caption Next If row.Table.Columns.Count * 100 + 30 > ScreenWidth Then dgvTreeView.Width = Me.Width - 30 Else dgvTreeView.Width = row.Table.Columns.Count * 100 + 30 ' 25 is for the column zero (+/-) End If dgvTreeView.Height = ScreenHeight - 100 'MsgBox(row.Table.Columns(0).Caption) ' statename 'MsgBox(row.ItemArray(0)) ' alaska - same as below... 'MsgBox(row.Field(Of String)(columnIndex:=0)) ' this works!!! End If dgx = dgx + 1 ' heading line - always have the element 0 as the first one. 'dgvTreeView.RowCount = dgvTreeView.RowCount + 1 'dgvTreeView.Columns(0).CellType.DataGridViewButtonColumn dgvTreeView.Rows(dgx).Cells(0).Value = "+" dgvTreeView.Columns(0).Width = 20 dgvTreeView.Rows(dgx).Cells(1).Value = row.ItemArray(0) ' row.Field(Of String)("StateName") ' detail line... dgx = dgx + 1 dgvTreeView.Rows(dgx).Cells(0).Value = "-" For xx = 1 To row.Table.Columns.Count - 1 dgvTreeView.Rows(dgx).Cells(xx + 1).Value = row.ItemArray(xx).ToString Next dgvTreeView.Rows.Item(dgx).Visible = False CountOfRows = CountOfRows + 1 Next adapter.Dispose() cmd.Dispose() CloseDB() End Sub Private Sub dgvTreeView_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvTreeView.CellClick iDGVRow = dgvTreeView.CurrentCell.RowIndex iDGVCol = dgvTreeView.CurrentCell.ColumnIndex ' this will only work if you have one parent row and one child row - if there are other combinations - ' perhaps 5 child rows? then you will need to change things... If iDGVCol = 0 Then If dgvTreeView.Rows(iDGVRow).Cells(0).Value = "-" Then dgvTreeView.Rows.Item(iDGVRow).Visible = False Else dgvTreeView.Rows.Item(iDGVRow + 1).Visible = True End If End If End Sub 'Private Sub SetupColumnHeadings() ' 'dgvTreeView.ColumnCount = Row.Table.Columns.Count + 1 ' 'dgvTreeView.Rows(dgx).Cells(0).Value = "+" ' 'For xx = 0 To Row.Table.Columns.Count - 1 ' ' dgvTreeView.Columns(xx + 1).HeaderText = Row.Table.Columns(xx).Caption ' 'Next ' 'If Row.Table.Columns.Count * 100 + 30 > ScreenWidth Then ' ' dgvTreeView.Width = Me.Width - 30 ' 'Else ' ' dgvTreeView.Width = Row.Table.Columns.Count * 100 + 30 ' 25 is for the column zero (+/-) ' 'End If ' 'dgvTreeView.Height = ScreenHeight - 100 ' 'MsgBox(row.Table.Columns(0).Caption) ' statename ' 'MsgBox(row.ItemArray(0)) ' alaska - same as below... ' 'MsgBox(row.Field(Of String)(columnIndex:=0)) ' this works!!! 'End Sub End Class
@jazzassin2150
@jazzassin2150 2 жыл бұрын
Hey that‘s great. Can you send me the Source Code?
@oakbank1953
@oakbank1953 2 жыл бұрын
Imports System.Data Imports System.Data.SqlClient Public Class frmUSAStates Private Sub frmUSAStates_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' www.sqlusa.com/bestpractices/dynamicsql/ ScreenWidth = Screen.PrimaryScreen.Bounds.Width ScreenHeight = Screen.PrimaryScreen.Bounds.Height Me.CenterToScreen() Dim adapter As New SqlDataAdapter Dim ds As New DataSet Dim CountOfRows As Integer = 0 sSQL = "select " sSQL = sSQL & "StateName, Abbreviation, Capital, LargestCity, Established, Population, " sSQL = sSQL & "Area_sqmiles, Area_sqkm, LandArea_sqmiles, LandArea_sqkm, WaterArea_sqmiles, WaterArea_sqkm, Representatives " sSQL = sSQL + "From tblUSAStates " sSQL = sSQL + "order by Abbreviation" OpenDB(sSQL) cmd.CommandText = sSQL cmd.ExecuteNonQuery() cmd = New SqlCommand(sSQL, cnn) adapter.SelectCommand = cmd adapter.Fill(ds) dgy = -1 dgx = -1 dgvTreeView.Rows.Clear() dgvTreeView.RowCount = 9999 For Each row As DataRow In ds.Tables(0).Rows If CountOfRows = 0 Then dgvTreeView.ColumnCount = row.Table.Columns.Count + 1 'dgvTreeView.Rows(dgx).Cells(0).Value = "+" For xx = 0 To row.Table.Columns.Count - 1 dgvTreeView.Columns(xx + 1).HeaderText = row.Table.Columns(xx).Caption Next If row.Table.Columns.Count * 100 + 30 > ScreenWidth Then dgvTreeView.Width = Me.Width - 30 Else dgvTreeView.Width = row.Table.Columns.Count * 100 + 30 ' 25 is for the column zero (+/-) End If dgvTreeView.Height = ScreenHeight - 100 'MsgBox(row.Table.Columns(0).Caption) ' statename 'MsgBox(row.ItemArray(0)) ' alaska - same as below... 'MsgBox(row.Field(Of String)(columnIndex:=0)) ' this works!!! End If dgx = dgx + 1 ' heading line - always have the element 0 as the first one. 'dgvTreeView.RowCount = dgvTreeView.RowCount + 1 'dgvTreeView.Columns(0).CellType.DataGridViewButtonColumn dgvTreeView.Rows(dgx).Cells(0).Value = "+" dgvTreeView.Columns(0).Width = 20 dgvTreeView.Rows(dgx).Cells(1).Value = row.ItemArray(0) ' row.Field(Of String)("StateName") ' detail line... dgx = dgx + 1 dgvTreeView.Rows(dgx).Cells(0).Value = "-" For xx = 1 To row.Table.Columns.Count - 1 dgvTreeView.Rows(dgx).Cells(xx + 1).Value = row.ItemArray(xx).ToString Next dgvTreeView.Rows.Item(dgx).Visible = False CountOfRows = CountOfRows + 1 Next adapter.Dispose() cmd.Dispose() CloseDB() End Sub Private Sub dgvTreeView_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvTreeView.CellClick iDGVRow = dgvTreeView.CurrentCell.RowIndex iDGVCol = dgvTreeView.CurrentCell.ColumnIndex ' this will only work if you have one parent row and one child row - if there are other combinations - ' perhaps 5 child rows? then you will need to change things... If iDGVCol = 0 Then If dgvTreeView.Rows(iDGVRow).Cells(0).Value = "-" Then dgvTreeView.Rows.Item(iDGVRow).Visible = False Else dgvTreeView.Rows.Item(iDGVRow + 1).Visible = True End If End If End Sub 'Private Sub SetupColumnHeadings() ' 'dgvTreeView.ColumnCount = Row.Table.Columns.Count + 1 ' 'dgvTreeView.Rows(dgx).Cells(0).Value = "+" ' 'For xx = 0 To Row.Table.Columns.Count - 1 ' ' dgvTreeView.Columns(xx + 1).HeaderText = Row.Table.Columns(xx).Caption ' 'Next ' 'If Row.Table.Columns.Count * 100 + 30 > ScreenWidth Then ' ' dgvTreeView.Width = Me.Width - 30 ' 'Else ' ' dgvTreeView.Width = Row.Table.Columns.Count * 100 + 30 ' 25 is for the column zero (+/-) ' 'End If ' 'dgvTreeView.Height = ScreenHeight - 100 ' 'MsgBox(row.Table.Columns(0).Caption) ' statename ' 'MsgBox(row.ItemArray(0)) ' alaska - same as below... ' 'MsgBox(row.Field(Of String)(columnIndex:=0)) ' this works!!! 'End Sub End Class
How I Beat The Password Game
39:53
Bog
Рет қаралды 2,3 МЛН
«Осень». Самая большая загадка Windows XP
14:36
Девять десятых
Рет қаралды 1 МЛН
2 MAGIC SECRETS @denismagicshow @roman_magic
00:32
MasomkaMagic
Рет қаралды 31 МЛН
Friends make memories together part 2  | Trà Đặng #short #bestfriend #bff #tiktok
00:18
Don't Use Polly in .NET Directly. Use this instead!
14:58
Nick Chapsas
Рет қаралды 69 М.
One CPU To Rule Them All - Ryzen 7 9800X3D Review
12:47
Linus Tech Tips
Рет қаралды 1,1 МЛН
The Logging Everyone Should Be Using in .NET
15:34
Nick Chapsas
Рет қаралды 80 М.
Donald Trump's full victory speech
26:31
FOX 9 Minneapolis-St. Paul
Рет қаралды 6 МЛН
How to Create a Data Entry Form in Excel
34:30
Excel Macro Mastery
Рет қаралды 294 М.
Coding Shorts 111: Was I Wrong About Blazor?
16:35
Shawn Wildermuth
Рет қаралды 17 М.
How to get started with VS Code
17:48
Kevin Powell
Рет қаралды 79 М.