Click here to Skip to main content
15,898,222 members
Home / Discussions / Windows Forms
   

Windows Forms

 
GeneralRe: DataGridView ComboBox VB.Net (Explaination) Pin
KiwiDanChCh28-Jul-09 8:53
KiwiDanChCh28-Jul-09 8:53 
GeneralRe: DataGridView ComboBox VB.Net (Explaination) Pin
Henry Minute28-Jul-09 8:55
Henry Minute28-Jul-09 8:55 
GeneralRe: DataGridView ComboBox VB.Net (Explaination) Pin
KiwiDanChCh29-Jul-09 0:05
KiwiDanChCh29-Jul-09 0:05 
GeneralRe: DataGridView ComboBox VB.Net (Explaination) Pin
KiwiDanChCh28-Jul-09 11:24
KiwiDanChCh28-Jul-09 11:24 
GeneralRe: DataGridView ComboBox VB.Net (Explaination) Pin
Henry Minute29-Jul-09 5:18
Henry Minute29-Jul-09 5:18 
GeneralRe: DataGridView ComboBox VB.Net (Explaination) Pin
KiwiDanChCh29-Jul-09 7:14
KiwiDanChCh29-Jul-09 7:14 
GeneralRe: DataGridView ComboBox VB.Net (Explaination) Pin
KiwiDanChCh1-Aug-09 18:52
KiwiDanChCh1-Aug-09 18:52 
GeneralRe: DataGridView ComboBox VB.Net (Explaination) Pin
Henry Minute2-Aug-09 4:49
Henry Minute2-Aug-09 4:49 
The following works as I think you described your requirements.

Public Class DGVComboIndexChangedForm
	Private productListMember As List(Of String) = New List(Of String)
	Dim HookedCombo As ComboBox

	Private Sub DGVComboIndexChangedForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		productListMember.Add("Product 1")
		productListMember.Add("Product 2")
		productListMember.Add("Product 3")

		CType(Me.dgvItems.Columns("ItemID"), DataGridViewComboBoxColumn).DataSource = Me.ProductList()
	End Sub

	Private Sub OnEditControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles dgvItems.EditingControlShowing
		If dgvItems.CurrentCell.ColumnIndex = 0 Then 'use the index for your comboboxcolumn
			HookedCombo = TryCast(e.Control, ComboBox)
			If HookedCombo Is Nothing Then
				Return
			End If
			AddHandler HookedCombo.SelectedIndexChanged, AddressOf OnComboIndexChanged
		End If
	End Sub

	Public Property ProductList()
		Get
			Return Me.productListMember
		End Get
		Set(ByVal value)
			Me.productListMember = value
		End Set
	End Property

	Private Sub OnComboIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
		Dim TheCombo As ComboBox = CType(sender, ComboBox)
		Dim strItemCode As String = Trim(TheCombo.Text)	'Value Of ComboBox

		Select Case (strItemCode)
			Case "Product 1"
				dgvItems.CurrentRow.Cells("ItemStock").Value = "1"
				dgvItems.CurrentRow.Cells("ItemPrice").Value = 1.1
			Case "Product 2"
				dgvItems.CurrentRow.Cells("ItemStock").Value = "2"
				dgvItems.CurrentRow.Cells("ItemPrice").Value = 2.2
			Case "Product 3"
				dgvItems.CurrentRow.Cells("ItemStock").Value = "3"
				dgvItems.CurrentRow.Cells("ItemPrice").Value = 3.3
		End Select

	End Sub
End Class


It is essentially as per the mods I suggested in my last post.

The class above is a Form with a DataGridView called dgvItems.
I manually added three columns to the grid using the Add Columns option from the Smart Tag on the DataGridView
1) DataGridViewComboBoxColumn named ItemID
2) DataGridViewTextBoxColumn named ItemStock
3) DataGridViewTextBoxColumn named ItemPrice

Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”

QuestionImplementing a Read-Only 'File Open' or 'File Save' Common Dialog [modified] Pin
easy games26-Jul-09 2:58
easy games26-Jul-09 2:58 
AnswerRe: Implementing a Read-Only 'File Open' or 'File Save' Common Dialog Pin
Mike Ellison27-Jul-09 2:33
Mike Ellison27-Jul-09 2:33 
GeneralRe: Implementing a Read-Only 'File Open' or 'File Save' Common Dialog Pin
easy games27-Jul-09 4:46
easy games27-Jul-09 4:46 
AnswerRe: Implementing a Read-Only 'File Open' or 'File Save' Common Dialog Pin
Dave Kreskowiak27-Jul-09 4:33
mveDave Kreskowiak27-Jul-09 4:33 
GeneralRe: Implementing a Read-Only 'File Open' or 'File Save' Common Dialog Pin
easy games27-Jul-09 5:23
easy games27-Jul-09 5:23 
GeneralRe: Implementing a Read-Only 'File Open' or 'File Save' Common Dialog Pin
Dave Kreskowiak27-Jul-09 6:48
mveDave Kreskowiak27-Jul-09 6:48 
GeneralRe: Implementing a Read-Only 'File Open' or 'File Save' Common Dialog Pin
easy games27-Jul-09 9:01
easy games27-Jul-09 9:01 
GeneralRe: Implementing a Read-Only 'File Open' or 'File Save' Common Dialog Pin
Dave Kreskowiak27-Jul-09 9:50
mveDave Kreskowiak27-Jul-09 9:50 
GeneralRe: Implementing a Read-Only 'File Open' or 'File Save' Common Dialog Pin
Mike Ellison27-Jul-09 10:22
Mike Ellison27-Jul-09 10:22 
GeneralRe: Implementing a Read-Only 'File Open' or 'File Save' Common Dialog Pin
easy games28-Jul-09 20:57
easy games28-Jul-09 20:57 
GeneralRe: Implementing a Read-Only 'File Open' or 'File Save' Common Dialog Pin
Mike Ellison29-Jul-09 5:42
Mike Ellison29-Jul-09 5:42 
QuestionAttractive programs that use Windows Forms to build their GUI Pin
copec25-Jul-09 18:48
copec25-Jul-09 18:48 
QuestionMake Dialer Pin
Any_India25-Jul-09 2:01
Any_India25-Jul-09 2:01 
Questioncan dragdrop in a listview? Pin
neodeaths24-Jul-09 19:10
neodeaths24-Jul-09 19:10 
AnswerRe: can dragdrop in a listview? Pin
Mike Ellison27-Jul-09 2:28
Mike Ellison27-Jul-09 2:28 
QuestionEvent Driven Form Pin
teknozwizard24-Jul-09 16:43
teknozwizard24-Jul-09 16:43 
AnswerRe: Event Driven Form Pin
Mycroft Holmes24-Jul-09 17:56
professionalMycroft Holmes24-Jul-09 17:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.