タイトル | : Re^3: 反復処理 |
記事No | : 991 |
投稿日 | : 2004/07/16(Fri) 15:06 |
投稿者 | : 緋色 |
DataGridTableStyle を使用し、DataGridTextBoxColumn を 下記のクラスに変更してみてください。
セル間の移動や、結合解除などは考慮していません。
Public Class MyDataGridTextBoxColumn Inherits System.Windows.Forms.DataGridTextBoxColumn
Protected Overloads Overrides Sub Edit( _ ByVal source As CurrencyManager, _ ByVal rowNum As Integer, _ ByVal bounds As Rectangle, _ ByVal read As Boolean, _ ByVal instantText As String, _ ByVal cellIsVisible As Boolean _ ) ComputeBounds(source, rowNum, bounds) MyBase.Edit(source, rowNum, bounds, read, instantText, cellIsVisible) End Sub
Protected Overrides Function Commit( _ ByVal dataSource As CurrencyManager, _ ByVal rowNum As Integer _ ) As Boolean Dim drv As DataRowView Dim map1 As String Dim map2 As String Dim obj1 As Object Dim obj2 As Object Dim result As Boolean
drv = CType(dataSource.List, DataView)(rowNum) map1 = DataGridTableStyle.GridColumnStyles(0).MappingName map2 = DataGridTableStyle.GridColumnStyles(1).MappingName obj1 = drv(map1) obj2 = drv(map2)
result = MyBase.Commit(dataSource, rowNum)
If result And Not drv.IsNew And obj1.Equals(obj2) Then Select Case DataGridTableStyle.GridColumnStyles.IndexOf(Me) Case 0 drv(map2) = drv(map1) Case 1 drv(map1) = drv(map2) End Select End If
Return result End Function
Protected Overloads Overrides Sub Paint( _ ByVal g As Graphics, _ ByVal bounds As Rectangle, _ ByVal source As CurrencyManager, _ ByVal rowNum As Integer, _ ByVal backBrush As Brush, _ ByVal foreBrush As Brush, _ ByVal alignToRight As Boolean _ ) ComputeBounds(source, rowNum, bounds) MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight) End Sub
Private Sub ComputeBounds( _ ByVal source As CurrencyManager, _ ByVal rowNum As Integer, _ ByRef bounds As Rectangle _ ) Dim dataGrid As DataGrid Dim drv As DataRowView Dim map1 As String Dim map2 As String Dim obj1 As Object Dim obj2 As Object
dataGrid = DataGridTableStyle.DataGrid drv = CType(source.List, DataView)(rowNum) map1 = DataGridTableStyle.GridColumnStyles(0).MappingName map2 = DataGridTableStyle.GridColumnStyles(1).MappingName obj1 = drv(map1) obj2 = drv(map2)
Select Case DataGridTableStyle.GridColumnStyles.IndexOf(Me) Case 0 To 1 If Not drv.IsNew And obj1.Equals(obj2) Then bounds.X = dataGrid.GetCellBounds(rowNum, 0).Left bounds.Width = dataGrid.GetCellBounds(rowNum, 1).Right - _ dataGrid.GetCellBounds(rowNum, 0).Left End If End Select End Sub
End Class
|