CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 30 of 30
  1. #16
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Editing Text in a DataGridViewComboBoxColumn

    That is good news! Great work guys!
    This was real fun for me!

  2. #17
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    Re: Editing Text in a DataGridViewComboBoxColumn

    Me too
    Visual Basic 2005 ver. 8.0.50727.867

  3. #18
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: Editing Text in a DataGridViewComboBoxColumn

    Glad it worked (I love it when something you program blind works, but I couldn't be bothered to switch between solutions

    You know, it wouldn't be far from the code we've got here to an extended DataGridView control where this was the default behaviour from all columns...

    Well, I've got nothing else to do this evening...
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  4. #19
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    Re: Editing Text in a DataGridViewComboBoxColumn

    LOL - good luck!!!

    right got wife's brother's wedding tomorrow so going for drinks with the Groom for his last night of freedom

    Have a good wekend everyone
    Visual Basic 2005 ver. 8.0.50727.867

  5. #20
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: Editing Text in a DataGridViewComboBoxColumn

    I had a go - the coding worked out simple. It compiles, but it crashes when you try and run a form with one on. Works fine on the designer, and it generates no debug data, so I'm stumped...
    Code:
    Public Class DataGridView2
            Inherits Windows.Forms.DataGridView
    
            Private Debounce As Boolean
    
            Private Sub mCellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles MyBase.CellValidating
                    If Debounce Then
                            Debounce = False
                    Else
                            If TypeOf (Me.Columns(e.ColumnIndex)) Is DataGridViewComboBoxColumn Then
                                    Dim comboBoxColumn As DataGridViewComboBoxColumn = CType(Me.Columns(e.ColumnIndex), DataGridViewComboBoxColumn)
                                    If (Not comboBoxColumn.Items.Contains(e.FormattedValue)) Then
                                            comboBoxColumn.Items.Add(e.FormattedValue)
                                            Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = comboBoxColumn.Items(comboBoxColumn.Items.Count - 1)
                                    End If
                            End If
                    End If
            End Sub
    
            Private Sub mColumnAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles MyBase.ColumnAdded
                    Debounce = True
            End Sub
    
            Private Sub DataGridView2_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles MyBase.EditingControlShowing
                    If TypeOf (MyBase.Columns(MyBase.CurrentCell.ColumnIndex)) Is DataGridViewComboBoxColumn Then
                            Dim cb As ComboBox = CType(e.Control, ComboBox)
                            If (cb IsNot Nothing) Then
                                    cb.DropDownStyle = ComboBoxStyle.DropDown
                            End If
                    End If
            End Sub
    End Class
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  6. #21
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Editing Text in a DataGridViewComboBoxColumn

    Good morning!

    This is what I did, javajawa :
    I created a Class Library called DGVNew, the code looks like :
    Code:
    Imports System.Windows.Forms.DataGridView
    Public Class DGVNew
        Inherits System.Windows.Forms.DataGridView
    
        Private Debounce As Boolean
    
        Private Sub DGVNew(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles MyBase.CellValidating
            If Debounce Then
                Debounce = False
            Else
                If TypeOf (Me.Columns(e.ColumnIndex)) Is System.Windows.Forms.DataGridViewComboBoxColumn Then
                    Dim comboBoxColumn As System.Windows.Forms.DataGridViewComboBoxColumn = CType(Me.Columns(e.ColumnIndex), System.Windows.Forms.DataGridViewComboBoxColumn)
                    If (Not comboBoxColumn.Items.Contains(e.FormattedValue)) Then
                        comboBoxColumn.Items.Add(e.FormattedValue)
                        Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = comboBoxColumn.Items(comboBoxColumn.Items.Count - 1)
                    End If
                End If
            End If
        End Sub
    
        Private Sub DGVNew(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles MyBase.ColumnAdded
            Debounce = True
        End Sub
    
        Private Sub DGVNew_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles MyBase.EditingControlShowing
            If TypeOf (MyBase.Columns(MyBase.CurrentCell.ColumnIndex)) Is System.Windows.Forms.DataGridViewComboBoxColumn Then
                Dim cb As System.Windows.Forms.ComboBox = CType(e.Control, System.Windows.Forms.ComboBox)
                If (cb IsNot Nothing) Then
                    cb.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown
                End If
            End If
        End Sub
    
    End Class
    Just had to reference System.Windows.Forms etc.

    I Built DGVNew, in order to get the DLL.
    Then, I created a separate project called DGVReplacement. I added the DGVNew.dll to the Toolbox, and added the following code :
    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim PenaltyColumn As New DataGridViewComboBoxColumn()
    
            With PenaltyColumn
                .DataPropertyName = "Penalty"
                .HeaderText = "Penalty"
                .DropDownWidth = 160
                .Width = 90
                .MaxDropDownItems = 3
                .FlatStyle = FlatStyle.Flat
                .Items.Add("1")
                .Items.Add("11")
    
            End With
            DgvNew1.Columns.Add(PenaltyColumn)
        End Sub
    End Class
    It works perfectly, I've been testing it for some time now, and I haven't had any problems with it

    Should I include them in a zip ( note it's in 2005, as I have 2008 only at home )

  7. #22
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: Editing Text in a DataGridViewComboBoxColumn

    Wouldn't mind the zip. My glitch probably came from the fact that I didn't bother with new projects, but just tore into the designer of the one I'd be using for this before. I probably made some mistake in there...
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  8. #23
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Editing Text in a DataGridViewComboBoxColumn

    Here is the zip

    I hope it helps!
    Last edited by HanneSThEGreaT; June 14th, 2010 at 05:39 AM.

  9. #24
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: Editing Text in a DataGridViewComboBoxColumn

    Found the issue - when I changed the designers, I forgot that it CTypes everything to call BeginInit(), so it was CTypeing to the old version. Plus Debugger was told not to show me that bit (there should be some options to turn that off by default. You can get so much fine tuning out of the designer...)
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  10. #25
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Editing Text in a DataGridViewComboBoxColumn

    Glad you got it solved!!

  11. #26
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: Editing Text in a DataGridViewComboBoxColumn

    Done some work on it - it now validates when you click elsewhere, or if you press enter. I can't work out why I need to do them sperately, but it works (surprisingly enough).

    I love pointless class design...
    Attached Files Attached Files
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  12. #27
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Editing Text in a DataGridViewComboBoxColumn

    Any objections on me setting up an FAQ covering DataGridViewComboboxColumns ( all these things we recenty did ) ¿

  13. #28
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: Editing Text in a DataGridViewComboBoxColumn

    Or even on some of the fun things you can do with DGVs generally? LOL
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  14. #29
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    Re: Editing Text in a DataGridViewComboBoxColumn

    Hi HannesTheGreat

    Sounds good to me!!
    Visual Basic 2005 ver. 8.0.50727.867

  15. #30
    Join Date
    May 2009
    Posts
    2

    Editing Text in a DataGridViewComboBoxColumn

    hi all.

    i hav added a datagricview into winform. i hav added 2 combobx column into that datagrid view.
    when i click the firsr combox column the second combobox column value should changed

    this is m y reqiurment was. my first combox column is Itemid and second combobx column is Itemdescription.

    as my reqirment when i chaged the itemid column the second column itemdescription should be changed.

    some one pls help mw for this.

    thnxs.
    Rishad...

Page 2 of 2 FirstFirst 12

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured