Results 1 to 2 of 2

Thread: [RESOLVED] DataGrid CustomColumnUpDown wierd behaviour

  1. #1
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 03
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    922

    Resolved [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
    Last edited by TDQWERTY; Jul 10th, 2010 at 06:53 AM. Reason: link
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  2. #2
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 03
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    922

    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
    Last edited by TDQWERTY; Jul 10th, 2010 at 07:32 AM.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •