Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DataGridView ComboBoxCell Editing Problem

Posted on 2007-04-09
8
Medium Priority
?
372 Views
Last Modified: 2012-08-13
I need to be able to edit the contents of a datagridview combobox cell or select one of the items in the dropdown list. If I understand the following statement from MSDN,
(http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcell.aspx)
 I should be able to do it:

The DataGridViewComboBoxCell class is a specialized type of DataGridViewCell used to display a combo box control, which is an editing field combined with a list selection field. The currently selected DataGridViewComboBoxCell hosts a DataGridViewComboBoxEditingControl in which the user can change the cell's value, assuming the cell's ReadOnly property is set to false.

I have set each cell's ReadOnly value to false using the following code,but it still only allows me to select from the dropdown list.

            With dgvStrataBdry
                For I = 0 To .RowCount - 1
                    .CurrentCell = Me.dgvStrataBdry(3, I)
                    .CurrentCell.ReadOnly = False
                Next
            End With

Am I misunderstanding that it should allow editing or just doing it wrong.


0
Comment
Question by:rkulp
[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
  • 6
  • 2
8 Comments
 
LVL 1

Author Comment

by:rkulp
ID: 18878684
I forgot to mention that the grid is unbound and all values are either programmatically set or entered by the user.
0
 
LVL 18

Accepted Solution

by:
Priest04 earned 2000 total points
ID: 18879625
No, changing ReadOnly will only allow/deny user to choose item from combobox. In order to allow typing in DataGridViewComboBox cell, you need to do 2 things

1) In DataGridView EditingControlShowing event set combobox DropDownStyle to DropDown

CType(e.Control, ComboBox).DropDownStyle = ComboBoxStyle.DropDown

that will allow editing, and

2) you need to manually add this new value to items collection
0
 
LVL 1

Author Comment

by:rkulp
ID: 18881793
Priest04,

Works like a champ. Thanks.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 18

Expert Comment

by:Priest04
ID: 18882045
You are welcome ;)
0
 
LVL 1

Author Comment

by:rkulp
ID: 18883829
I spoke too quickly. Evidently I don't know how to properly address the column to change the value. I can enter the value in the cell (where I couldn't before) but when I leave the cell (which I neglected to do earler in my rush to get to jury duty) the value returns to one of the previously set items. Apparently I did not set the items correctly. Here is the code. Please show me the correct way.

        With dgvStrataBdry
            If e.ColumnIndex = 3 Then
                dgvStrataBdry.CurrentCell = Me.dgvStrataBdry(e.ColumnIndex, e.RowIndex)
                Select Case .CurrentCell.Value
                    Case "No"
                        AuditInfo.CensusFlag(e.RowIndex) = False
                        AuditInfo.NHh(e.RowIndex) = 0
                    Case "Yes"
                        AuditInfo.CensusFlag(e.RowIndex) = True
                        AuditInfo.NHh(e.RowIndex) = AuditInfo.Nh(e.RowIndex)
                    Case Else
                        AuditInfo.CensusFlag(e.RowIndex) = False
                        AuditInfo.NHh(e.RowIndex) = CType(.CurrentCell.Value, Integer)
                        Dim cbcol As DataGridViewComboBoxColumn
                        cbcol = dgvStrataBdry.Columns(3)
                        cbcol.Items.Add(.CurrentCell.Value)

                End Select
            End If
0
 
LVL 1

Author Comment

by:rkulp
ID: 18883851
The code above is in:

    Private Sub dgvStrataBdry_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvStrataBdry.CellValueChanged

Maybe that is not the correct place for it.
0
 
LVL 1

Author Comment

by:rkulp
ID: 18883997
I also have tried the following which I found elsewhere in E-E. It does not work.
   Dim cb As New DataGridViewComboBoxCell
       cb = DataGridView1(comboboxcolumnindex, row index)
       cb.items.add("xyz")

I don't want to artificially superimpose a text box on top of the cell to capture the information and then put its value in the items. I hope there is a better way. I'm just too dense to see it.
0
 
LVL 1

Author Comment

by:rkulp
ID: 18894083
This seems to work:

    Private Sub dgvStrataBdry_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvStrataBdry.EditingControlShowing
        If dgvStrataBdry.CurrentCellAddress.X = 3 Then
            CType(e.Control, ComboBox).DropDownStyle = ComboBoxStyle.DropDown
        End If
    End Sub
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 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