Results 1 to 40 of 41

Thread: [.NET 2.0+] Adding a ComboBox Column to a DataGridView

Threaded View

  1. #11
    Junior Member
    Join Date
    Sep 2008
    Posts
    17

    Re: [.NET 2.0+] Adding a ComboBox Column to a DataGridView

    Nice work

    But i have one problem and dont know how to solve it. I already have appplication with a lot of combos and textboxes on form (32 rows, in each row 5 combos and 5 texboxes and lot of code behind). Problem is that curent app is very slow on form load. With your sample i could make it a lot faster.

    Already have gridview filled with some test data.

    And the problem is:

    When i click on combobox in use this code to display dropdown (to click only once to display dropdown).

    Code:
    Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
            Try
                If e.RowIndex = -1 Then Exit Sub
                Select Case e.ColumnIndex
                    Case 0, 2, 4, 6, 8
                        DataGridView1.BeginEdit(True)
    
                        Dim controll As DataGridViewComboBoxEditingControl = DataGridView1.EditingControl
                        If controll IsNot Nothing Then
                            controll.DroppedDown = True
    
                        End If
    
                End Select
            Catch ex As Exception
                MsgBox(ex.Message & "  " & e.RowIndex & "  " & e.ColumnIndex)
            End Try
    
        End Sub
    
        Private Sub gwKupuje_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
            If e.Context = DataGridViewDataErrorContexts.Formatting _
                   Or e.Context = DataGridViewDataErrorContexts.PreferredSize Then
                e.ThrowException = False
            End If
        End Sub
    When i click on item in dropdown the cell is filled with selected text. But CellValueChanged event is fired when i go out from cel in clicked on other cell. Now how i set that value is changed when i click on item in dropdown, or to catch this event?

    I need this for enable or disable (ready only) next cell in gridview.

    An one more thing.

    I want to add one column in gridview like row number, starting with 0.
    Last edited by kotlet; Oct 29th, 2010 at 12:28 AM.

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