[RESOLVED] DataGrid CustomColumnUpDown wierd behaviour
Is there anything wrong with my code? The column doesn't have the expected behavior, nor it does respect the width values..
Code:
Code:
Private Sub testDataGrid()
Dim myDataSet2 As New DataSet
Dim myDataTable As New DataTable
Dim aGridTableStyle2 As New DataGridTableStyle
Dim dataGridCustomColumn2 As New DataGridCustomUpDownColumn
With dataGridCustomColumn2
.Owner = Me.DataGrid1
.HeaderText = "Quantity"
.MappingName = "Quantity"
.NullText = "-Unknown-"
.Width = DataGrid1.Width
.Alignment = HorizontalAlignment.Left
.AlternatingBackColor = Color.Aqua
End With
With aGridTableStyle2.GridColumnStyles
.Add(dataGridCustomColumn2)
End With
DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(aGridTableStyle2)
myDataSet2 = New DataSet("myDataSet2")
Dim tCust As New DataTable("Customers")
Dim dQuantity As New DataColumn("Quantity", GetType(Decimal))
tCust.Columns.Add(dQuantity)
myDataSet2.Tables.Add(tCust)
Dim newRow1 As DataRow
Dim i As Decimal
For i = 1 To 20
newRow1 = tCust.NewRow()
newRow1("Quantity") = i
tCust.Rows.Add(newRow1)
Next i
myDataTable = myDataSet2.Tables("Customers")
DataGrid1.DataSource = myDataTable
End Sub
Class:
Code:
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Public Class DataGridCustomUpDownColumn
Inherits DataGridCustomColumnBase
Private _nullValue As [Decimal] = -1
Public Overloads Overrides Property NullValue() As Object
Get
Return _nullValue
End Get
Set
If Not (TypeOf value Is [Decimal]) Then
Throw New ArgumentException("Value sould be of type Decimal for this property.")
End If
If CType(value, [Decimal]) <> _nullValue Then
_nullValue = CType(value, [Decimal])
Me.Owner.Invalidate()
End If
End Set
End Property
' Let's add this so user can access control
Public Overridable ReadOnly Property NumericUpDown() As NumericUpDown
Get
Return TryCast(Me.HostedControl, NumericUpDown)
End Get
End Property
Protected Overloads Overrides Function GetBoundPropertyName() As String
Return "Value"
' We'll bind to "Value" property.
End Function
Protected Overloads Overrides Function CreateHostedControl() As Control
Dim nud As New NumericUpDown()
' Just create new control.
nud.Minimum = -1
Return nud
End Function
End Class
(class obtained from Here)
The UpDown control doesn't show, those cells act as a readonly textbox and the column width is different from what's expected (same size as the column headerText)
Thanks in advance
Re: DataGrid CustomColumnUpDown wierd behaviour
There is missing:
aGridTableStyle2.MappingName
Plus, the column was too big, after setting the column to 1/3 of the grid size it started working as expected :confused: