Solved

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

Posted on 2011-09-06
3
528 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 500 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

695 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