Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to change the cell value of datagridview when Datagridview combobox index is changed

Posted on 2010-01-06
3
Medium Priority
?
1,708 Views
Last Modified: 2012-05-08
II need to display the data in datagridview for my program in vb.net.it has three column and first one is combobox column and second one is textcolumn and third one also combobox.
Depends on the selection of  first combobox ,value of second text column has to be changed and same time third combobox text collection also has to be changed.

How to make changes when first combobox selected index changed in vb.net?

Thanks
0
Comment
Question by:Nitharsan
  • 2
3 Comments
 
LVL 4

Expert Comment

by:rdoran0928
ID: 26201497
You need to handle the DataGridView's CellValueChanged event and do something like the following:

    Private Sub myDataGridView_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
    Handles myDataGridView.CellValueChanged

        ' check if column 0 cell has changed
        If e.RowIndex <> -1 AndAlso e.ColumnIndex = 0 Then

            ' change column 1 cell value
            curPartiesRow.Cells(1).Value = someNewValue

        End If

    End Sub
0
 
LVL 4

Expert Comment

by:rdoran0928
ID: 26201552
I copied some code incorrectly.  The line

curPartiesRow.Cells(1).Value = someNewValue

should actually be:

myDataGridView.Rows(e.RowIndex).Cells(1).Value = someNewValue


0
 

Accepted Solution

by:
Nitharsan earned 0 total points
ID: 26493258
I found a solution...

Private Sub dgBrake_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgBrake.EditingControlShowing

             
            dgComboBox = TryCast(e.Control, ComboBox)
            If (TypeOf e.Control Is DataGridViewComboBoxEditingControl) Then
                Dim cmb As DataGridViewComboBoxEditingControl = CType(e.Control, DataGridViewComboBoxEditingControl)

                If Not cmb Is Nothing Then
                    RemoveHandler dgComboBox.SelectedIndexChanged, AddressOf Me.dgComboBox_SelectedIndexChanged

                    AddHandler dgComboBox.SelectedIndexChanged, AddressOf Me.dgComboBox_SelectedIndexChanged
                Else
                    Exit Sub

                End If
            End If
     


    End Sub

    Private Sub dgComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        If rowindex1 = 1 Then
            Dim cmbBox As ComboBox = DirectCast(sender, ComboBox)
            If cmbBox.SelectedIndex = 0 Then
                'Add code here
            ElseIf cmbBox.SelectedIndex = 1 Then
                 'Add code here
            End If
        End If

    End Sub
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question