C# と VB.NET の質問掲示板

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト

DataGridViewのColumnとRowのスクロールしたときの位置について


(過去ログ 5 を表示中)

[トピック内 3 記事 (1 - 3 表示)]  << 0 >>

■5320 / inTopicNo.1)  DataGridViewのColumnとRowのスクロールしたときの位置について
  
□投稿者/ まじん 二等兵(8回)-(2006/08/06(Sun) 13:46:53)

分類:[C#] 


分類:[C#] 

No5308で投稿させていただいた DataGridViewのヘッダーの結合で スクロールさせるとヘッダー部分が付いていかない事が分かりました

スクロールさせた時のColumnやRowの位置関係が取得できれば改良できるかと考えたのですが その位置関係を取得する方法がわかりません
御教授いただけないでしょうか?


0
引用返信 編集キー/
■5321 / inTopicNo.2)  Re[1]: DataGridViewのColumnとRowのスクロールしたときの位置について
□投稿者/ まじん 二等兵(9回)-(2006/08/06(Sun) 14:43:25)

分類:[C#] 

No5320に返信(まじんさんの記事)
.FirstDisplayedScrollingColumnHiddenWidthと
.FirstDisplayedScrollingColumnIndex()を組み合わせる事で 取得できることがわかりましたので 改良してみます。

0
引用返信 編集キー/
■5374 / inTopicNo.3)  Re[2]: DataGridViewのColumnとRowのスクロールしたときの位置について
□投稿者/ まじん 二等兵(10回)-(2006/08/08(Tue) 20:10:42)

分類:[C#] 

No5321に返信(まじんさんの記事)

なんとか 完成しました

Imports System.Windows.Forms
Imports System.Drawing
Public Class GridViewSP
Inherits Windows.Forms.DataGridView
Dim Pan As Panel
Dim _HedSet() As String
Dim FastSet As Boolean = False
Dim _ColCoun As Integer = 30
Dim _Lab(_ColCoun) As Label
Dim _Set(_ColCoun) As Integer
Dim _HedColor As Color = System.Drawing.SystemColors.Control

Public Sub New()

Pan = New Panel
Console.WriteLine("new")
Dim c As Integer
Do
_Lab(c) = New Label
Pan.Controls.Add(_Lab(c))
_Lab(c).Visible = False
c += 1
Loop Until c >= _ColCoun
If HedSet Is Nothing Then Exit Sub

End Sub
Public Function HedLab() As ArrayList
_colcoun = Me.columns.count - 1
Dim l As Integer = 0
Do
_Set(l) = l
l += 1
Loop Until l >= _ColCoun + 1
Dim Hed As New ArrayList
Dim lab As New ArrayList
For Each c As String In HedSet
Dim labNo As Integer
labNo = CInt(Mid(c, 1, 2))
lab.Add(labNo)
Dim co As Integer = CInt(Mid(c, 3, 2))
If co > 1 Then
For i As Integer = 0 To co - 2
lab.Add(labNo + i + 1)
Next
End If
Next
For Each cc As Integer In _Set
Dim ari As Integer = 0
Dim ccc As Integer
For Each ccc In lab
If cc = ccc Then
ari = 1
Exit For
End If
Next
If ari = 0 Then
Hed.Add(cc)
End If
Next
Return Hed
End Function
Public Property HedColor() As Color
Get
HedColor = _HedColor
End Get
Set(ByVal value As Color)
_HedColor = value
End Set
End Property
Public Property HedSet() As String()
Get
HedSet = _HedSet
End Get
Set(ByVal value As String()) 'ここは結合したい列を 結合したいところだけ 例えば2列目から4列分結合したいなら 4桁の文字列で”0204”というふうに入力
_HedSet = value
End Set
End Property
Public Sub HedSetting2()
If HedSet Is Nothing Then Exit Sub
If HedSet.Length < 1 Then
Pan.Visible = False
Exit Sub
End If
If FastSet = True Then Exit Sub

If Me.Columns.Count > 0 Then
If Not HedSet Is Nothing Then
Pan.Visible = True

Dim par As Control = Me.Parent
par.Controls.Add(Pan)
Pan.BringToFront()

Dim len As Integer = HedSet.Length
If len < 1 Then Exit Sub
Me.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
Dim fon As Font = Me.ColumnHeadersDefaultCellStyle.Font

Dim f As Integer = 0

With Pan
.BorderStyle = Windows.Forms.BorderStyle.None
.Top = Me.Top + 1
.Left = Me.Left + Me.RowHeadersWidth
.Width = Me.Width - Me.RowHeadersWidth - 17
.Height = Me.ColumnHeadersHeight
.Visible = True
End With

Dim ii As Integer = 0

For Each c As String In HedSet

Dim st As String = c
Dim setHed As Integer = CInt(Mid(st, 1, 2))
Dim setCou As Integer = CInt(Mid(st, 3, 2))
Dim lef As Integer = 0
Dim top As Integer = Me.Top
Dim wid As Integer = 0
Dim hig As Integer = Me.ColumnHeadersHeight
lef = Me.RowHeadersWidth
Dim lef2 As Integer = 0
If setHed > 1 Then
For i As Integer = 0 To setHed - 2
lef2 = lef2 + Me.Columns(i).Width
Next
End If
lef = lef + Me.Left
Dim l As Integer = 0
Do
wid = wid + Me.Columns(setHed - 1 + l).Width
l += 1
Loop Until l >= setCou
If Not _Lab Is Nothing Then
With _Lab(ii)
.AutoSize = False
.Top = 0
.Left = lef2
.Tag = lef2
.Width = wid
.Height = hig
.BorderStyle = Windows.Forms.BorderStyle.FixedSingle
.BackColor = HedColor
.Text = Me.Columns(setHed - 1).HeaderText
.TextAlign = ContentAlignment.MiddleCenter
.Font = fon
.BringToFront()
.Visible = True
End With
End If
f += 1
ii += 1
Next
For Each cc As Integer In HedLab()
If cc > 0 Then
Dim st As String = cc
Dim setHed As Integer = cc
Dim setCou As Integer = 1
Dim lef As Integer = 0
Dim top As Integer = Me.Top
Dim wid As Integer = 0
Dim hig As Integer = Me.ColumnHeadersHeight
lef = Me.RowHeadersWidth
Dim lef2 As Integer = 0
If setHed > 1 Then
For i As Integer = 0 To setHed - 2
lef2 = lef2 + Me.Columns(i).Width
Next
End If
lef = lef + Me.Left

wid = Me.Columns(setHed).Width

With _Lab(cc)
.AutoSize = False
.Top = 0
.Left = lef2
.Tag = lef2
.Width = wid
.Height = hig
.BorderStyle = Windows.Forms.BorderStyle.FixedSingle
.BackColor = HedColor
.Text = Me.Columns(setHed - 1).HeaderText
.TextAlign = ContentAlignment.MiddleCenter
.Font = fon
.BringToFront()
.Visible = True
End With
End If
Next
End If
End If
End Sub

Private Sub GridViewSP_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
If Not Pan Is Nothing Then Pan.Dispose()
For Each l As Label In _Lab
If Not l Is Nothing Then l.Dispose()
Next
End Sub

Private Sub GridViewSP_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If FastSet = False Then
HedSetting2()
FastSet = True
Me.Refresh()
End If
End Sub

Private Sub GridViewSP_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles Me.Scroll
If _Lab Is Nothing Then Exit Sub
Dim Shado As Object = Me.FirstDisplayedScrollingColumnHiddenWidth
Dim NowInd As Object = Me.FirstDisplayedScrollingColumnIndex()
Dim ShadWid As Integer
If NowInd > 0 Then
For i As Integer = 0 To NowInd - 1
ShadWid = ShadWid + Me.Columns(i).Width
Next
End If
ShadWid = ShadWid + Shado

For Each c As Label In _Lab
If Not c Is Nothing Then
c.Left = CInt(c.Tag) - ShadWid
End If
Next
End Sub
End Class


0
引用返信 編集キー/


トピック内ページ移動 / << 0 >>

このトピックに書きこむ

過去ログには書き込み不可

管理者用

- Child Tree -