[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Need assistance with DataGridViewComboBoxCoumn

Posted on 2015-02-04
2
Medium Priority
?
62 Views
Last Modified: 2015-02-09
Experts, I am experiencing a strange thing with my DataGridViewComboBoxColumn. Below is the code I am using. I need to set the value in a datatable to the selected index of the combo box. Everything works fine until it encounters this line.

row("GroupID") = combo.SelectedIndex.

As soon as it hits this line it immediately exits the method. Also, it sets the combo box selected index to 0 (zero). I can see my selection in the combo box very briefly before it changes back to an index of 0. I know it is this line because I can comment it out and then everything begins working correctly. I have also tried the "SelectionChangeCommitted" event and while it should only fire once, this line is causing it to fire as many as ten times.

Can anyone help me with this problem?
DataGridView1.DataSource = ds.tables("dtProjectItems")
       
 Dim dt As New DataTable
        With dt
            .Columns.Add("ID", GetType(Integer))
            .Columns.Add("Text", GetType(String))
            .Rows.Add(0, "NONE")
            .Rows.Add(1, "OPTION")
            .Rows.Add(2, "SPARE")
            .Rows.Add(3, "CONSUMABLE")
        End With
        Dim ccolumn As New DataGridViewComboBoxColumn
        With ccolumn
            .DataSource = dt
            .DisplayMember = "Text"
            .ValueMember = "ID"
            .Name = "COMBO"
        End With    

Private Sub DataGridView2_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView2.EditingControlShowing
        If TypeOf e.Control Is ComboBox Then
            Dim combo As ComboBox = CType(e.Control, ComboBox)
            If combo IsNot Nothing Then
                RemoveHandler combo.SelectedIndexChanged, AddressOf DataGridViewCombo_SelectedIndexChanged
                AddHandler combo.SelectedIndexChanged, AddressOf DataGridViewCombo_SelectedIndexChanged
            End If
        End If
    End Sub

    Private Sub DataGridViewCombo_SelectedIndexChanged(sender As Object, e As EventArgs)
        Dim combo As ComboBox = CType(sender, ComboBox)
        If combo.SelectedIndex > -1 Then
            Dim row As DataRow = ds.Tables("dtProjectItems").Rows.Find(DataGridView2.SelectedRows(0).Cells("ID").Value)
            RemoveHandler combo.SelectedIndexChanged, AddressOf DataGridViewCombo_SelectedindexChanged
           row("GroupID") = combo.SelectedIndex
        End If
    End Sub

Open in new window

0
Comment
Question by:Basicfarmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 40596975
Are you sure that "row" is actually set to a value in line 33? In that line, if your Find operation does not return a value, then your "row" object may not be valid.
0
 

Author Closing Comment

by:Basicfarmer
ID: 40599500
Thanks for the comment Scott. That was the issue, the row was not valid...
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

650 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