?
Solved

How can I set the equivlent of the "selectedIndex" of a DataGridViewComboboxCell?

Posted on 2011-09-06
3
Medium Priority
?
531 Views
Last Modified: 2012-05-12
Basically, I want to set a "SelectedIndex" value of the comboboxcell.

From the code shown, objTypes object will contain something like:-
Value          Desc
10               First
20               Second
30               Third
etc....

I want to default some of the rows to specific values.  If I set the ".Value" property of the cell to 20, I want this to display "Second" within the combobox cell but I get the error attached as screen shot:-

Any help would be appreciated
 Error screen shot
Dim dgCombo As DataGridViewComboBoxCell = grdHeader.Rows(i).Cells("colType")
dgCombo.DataSource = objTypes
dgCombo.DisplayMember = "Desc"
dgCombo.ValueMember = "Value"

Open in new window

0
Comment
Question by:bmsdev
[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
3 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 total points
ID: 36489529
Dim dgCombo As DataGridViewComboBoxCell = grdHeader.Rows(i).Cells("colType")
dgCombo.DisplayMember = "Desc" 'With this you say that the combo must show the "Desc" value of each object added
dgCombo.ValueMember = "Value" 'With this you say that the value member of each object is the "Value" property or field
dgCombo.DataSource = objTypes 'Set the data source

dgCombo.Value = 4 'For example, with this the object with the value 4 in the "Value" property or field will be selected

Hope that helps.
0
 
LVL 15

Expert Comment

by:x77
ID: 36489586
A ComboBoxCell contains a ComboBox only when the cell is in Edit Mode.

Dgv has only One ComboBox or Textbox ... intance for all Cells.
Then you can access to Cell Control only when the Cell is in Edit Mode.

To Get the Control, you can use the Event Dgv_EditingControlShowing.
   At this point you can use E.Control and cast it to use apropiate methods an properties.
   Dgv_EditModeChanged, notifies edit mode changes.

At Cell Level, you can Override InitializeEditingControl and DetachEditingControl.

You can get the EditingControl from Dgv an cast It, but it is valid when cell is editing mode.

   Dim Cmb = TryCast(Dgv.Editingcontrol,DataGridViewComboBoxEditingControl)
   if cmb isnot nothing ....
0
 

Author Closing Comment

by:bmsdev
ID: 36489592
That worked perfictly.  I did origionally have that code, but the ".Value" property is a Decimal, and i was setting it to an Integer.  Thanks for you help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

765 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