Column Style

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • EdB

    Column Style

    Is there a way, without going to a 3rd party product, to make a column in a
    datagrid a drop down list? Or to otherwise limit the users ability for entry
    in a particular column to two or three possibilities (other than coded
    validation after entry)?
  • Chris Podmore

    #2
    RE: Column Style

    Have a look at the MSDN articles about customising the DataGrid.





    Chris.

    "EdB" wrote:
    [color=blue]
    > Is there a way, without going to a 3rd party product, to make a column in a
    > datagrid a drop down list? Or to otherwise limit the users ability for entry
    > in a particular column to two or three possibilities (other than coded
    > validation after entry)?[/color]

    Comment

    • Cor Ligthert

      #3
      Re: Column Style

      Ed

      In this message is a combobox sample that I once made.



      I hope this helps,

      Cor


      Comment

      • EdB

        #4
        Re: Column Style

        Cor,

        This slipped right in for me....thanks. But I'm getting some rather funky
        behavior after I select. When the combo box loses focus, it has a tendency
        to revert back to the first item, even after I have selected the second. Any
        thoughts?

        "Cor Ligthert" wrote:
        [color=blue]
        > Ed
        >
        > In this message is a combobox sample that I once made.
        >
        > http://groups-beta.google.com/group/...9573dbe957f4ee
        >
        > I hope this helps,
        >
        > Cor
        >
        >
        >[/color]

        Comment

        • Cor Ligthert

          #5
          Re: Column Style

          Ed,

          Are you sure, I tried the sample again from my message and now Herfried
          lives in Holland and Jay in Austria and they stay there.

          Cor


          Comment

          • Andy O'Neill

            #6
            Re: Column Style


            "EdB" <EdB@discussion s.microsoft.com > wrote in message
            news:99011BC3-64A7-4E07-BC60-70448530C01F@mi crosoft.com...[color=blue]
            > Cor,
            >
            > This slipped right in for me....thanks. But I'm getting some rather funky
            > behavior after I select. When the combo box loses focus, it has a
            > tendency
            > to revert back to the first item, even after I have selected the second.
            > Any
            > thoughts?
            >
            > "Cor Ligthert" wrote:
            >[color=green]
            >> Ed
            >>
            >> In this message is a combobox sample that I once made.
            >>
            >> http://groups-beta.google.com/group/...9573dbe957f4ee
            >>
            >> I hope this helps,
            >>
            >> Cor[/color][/color]

            I use something very very similar based on George shepherd's FAQ,
            When I used the code it had a problem.
            Can't recall exactly what.
            It was far too much trouble to try a different method or rewrite from
            scratch so I tinkered a bit.
            You can just cut and paste the code and see if your problem goes away.

            =============== ======


            Public Class DataGridComboBo xColumn
            Inherits DataGridTextBox Column
            ' use the derived nokeyup combo to avoid tabbing problem
            Public WithEvents ColumnComboBox As NoKeyUpCombo

            Private WithEvents _source As CurrencyManager
            Private _rowNum As Integer
            Private _isEditing As Boolean

            Shared Sub New()
            'Warning: Implementation not found
            End Sub
            Public Sub New()
            MyBase.New()

            _source = Nothing
            _isEditing = False


            ColumnComboBox = New NoKeyUpCombo()
            AddHandler ColumnComboBox. Leave, New EventHandler(Ad dressOf
            LeaveComboBox)
            AddHandler ColumnComboBox. SelectionChange Committed, New
            EventHandler(Ad dressOf ComboStartEditi ng)

            End Sub
            Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager ,
            ByVal rowNum As Integer, ByVal bounds As Rectangle, ByVal readOnly1 As
            Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
            MyBase.Edit(sou rce, rowNum, bounds, readOnly1, instantText,
            cellIsVisible)
            _rowNum = rowNum
            _source = source
            ColumnComboBox. Parent = Me.TextBox.Pare nt
            ColumnComboBox. Location = Me.TextBox.Loca tion
            ColumnComboBox. Size = New Size(Me.TextBox .Size.Width,
            ColumnComboBox. Size.Height)
            ColumnComboBox. Text = Me.TextBox.Text
            Me.TextBox.Visi ble = False
            ColumnComboBox. Visible = True
            ColumnComboBox. BringToFront()
            ColumnComboBox. Focus()
            End Sub
            Protected Overloads Overrides Function Commit(ByVal dataSource As
            CurrencyManager , ByVal rowNum As Integer) As Boolean

            If _isEditing Then
            _isEditing = False
            SetColumnValueA tRow(dataSource , rowNum, ColumnComboBox. Text)
            End If
            Return True

            End Function
            Private Sub ComboStartEditi ng(ByVal sender As Object, ByVal e As
            EventArgs)

            _isEditing = True
            MyBase.ColumnSt artedEditing(se nder)
            End Sub
            Private Sub LeaveComboBox(B yVal sender As Object, ByVal e As EventArgs)

            If _isEditing Then
            SetColumnValueA tRow(_source, _rowNum, ColumnComboBox. Text)
            _isEditing = False
            Invalidate()
            End If
            ColumnComboBox. Hide()

            End Sub
            End Class


            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: Column Style

              Cor,

              "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue]
              > Are you sure, I tried the sample again from my message and now Herfried
              > lives in Holland and Jay in Austria and they stay there.[/color]

              LOL ;-).

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

              Comment

              Working...