Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now