Click here to Skip to main content
15,892,643 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Check file infection by CRC32 Pin
Gagan.204-Dec-09 14:56
Gagan.204-Dec-09 14:56 
QuestionPivotTable Strategery Pin
Bomb_shell3-Dec-09 11:31
Bomb_shell3-Dec-09 11:31 
AnswerRe: PivotTable Strategery Pin
freakyit4-Dec-09 4:06
freakyit4-Dec-09 4:06 
GeneralRe: PivotTable Strategery Pin
Bomb_shell10-Dec-09 5:20
Bomb_shell10-Dec-09 5:20 
QuestionVB.Net MTAThread attribute (.Net 3.5) Pin
#realJSOP3-Dec-09 5:21
mve#realJSOP3-Dec-09 5:21 
AnswerRe: VB.Net MTAThread attribute (.Net 3.5) Pin
Duncan Edwards Jones3-Dec-09 5:42
professionalDuncan Edwards Jones3-Dec-09 5:42 
AnswerRe: VB.Net MTAThread attribute (.Net 3.5) Pin
Rama Krishna Vavilala3-Dec-09 5:48
Rama Krishna Vavilala3-Dec-09 5:48 
QuestionUsing Combobox as DataGridViewColumn Pin
EvanSaunders3-Dec-09 2:37
EvanSaunders3-Dec-09 2:37 
Hi All

I've been adding textboxes, numericupandowns, etc. to the dataGridView Column, and everything was working fine. I even successfully added a combobox to the datagridview column.
However, I have hit a brick wall and can't find my way around it.
I am trying to load items into the combobox (based on items from the database), and then add the combobox to the datagridview. Note that each item that is in the datagrid has its own set of items to be added to the combobox, so when I select any item, I want to be able to use the combobox as a drop down list to select from the list of options.

I have implemented the datagridview column for the combobox and named it 'DropDownColumn'.
Also created the cell and editing control named 'DropDownCell' and 'DropDownEditingControl', respectively.

I don't know how to add individual items into each of the comboboxes for the given items.
My code looks like this:

Public Class DropDownColumn
Inherits DataGridViewColumn

Public Event Change(ByVal sender As Object, ByVal e As System.EventArgs)

Public Sub New()
MyBase.New(New DropDownCell())
End Sub

Public Overrides Property CellTemplate() As DataGridViewCell
Get
Return MyBase.CellTemplate
End Get
Set(ByVal value As DataGridViewCell)
If (value IsNot Nothing) AndAlso Not value.GetType().IsAssignableFrom(GetType(DropDownCell)) Then
Throw New InvalidCastException("Must be a DropDownCell")
End If
MyBase.CellTemplate = value
End Set
End Property
End Class

--------------------------------------

Public Class DropDownCell
Inherits DataGridViewTextBoxCell

Public Sub New()
End Sub

Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle)
MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
Dim ctl As DropDownEditingControl = CType(DataGridView.EditingControl, DropDownEditingControl)
End Sub

Public Overrides ReadOnly Property EditType() As Type
Get
Return GetType(DropDownEditingControl)
End Get
End Property

Public Overrides ReadOnly Property ValueType() As Type
Get
Return GetType(String)
End Get
End Property

Public Overrides ReadOnly Property DefaultNewRowValue() As Object
Get
Return 0
End Get
End Property
End Class

--------------------------

Public Class DropDownEditingControl
Inherits ComboBox
Implements IDataGridViewEditingControl

Private dataGridViewControl As DataGridView
Private valueIsChanged As Boolean = False
Private rowIndexNum As Integer

Public Sub New()
End Sub

Public Property EditingControlFormattedValue() As Object Implements IDataGridViewEditingControl.EditingControlFormattedValue
Get
Return Me.Text
End Get

Set(ByVal value As Object)
If TypeOf value Is String Then
Me.Text = CStr(value)
End If
End Set
End Property

Public Function GetEditingControlFormattedValue(ByVal context As DataGridViewDataErrorContexts) As Object Implements IDataGridViewEditingControl.GetEditingControlFormattedValue
Return Me.Text.ToString()
End Function

Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As DataGridViewCellStyle) Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl
Me.Font = dataGridViewCellStyle.Font
Me.ForeColor = dataGridViewCellStyle.ForeColor
Me.BackColor = dataGridViewCellStyle.BackColor
End Sub

Public Property EditingControlRowIndex() As Integer Implements IDataGridViewEditingControl.EditingControlRowIndex
Get
Return rowIndexNum
End Get
Set(ByVal value As Integer)
rowIndexNum = value
End Set
End Property

Public Function EditingControlWantsInputKey(ByVal key As Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean Implements IDataGridViewEditingControl.EditingControlWantsInputKey
Select Case key And Keys.KeyCode
Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp
Return True
Case Else
Return Not dataGridViewWantsInputKey
End Select
End Function

Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) Implements IDataGridViewEditingControl.PrepareEditingControlForEdit
' No preparation needs to be done.
End Sub

Public ReadOnly Property RepositionEditingControlOnValueChange() As Boolean Implements IDataGridViewEditingControl.RepositionEditingControlOnValueChange
Get
Return False
End Get
End Property

Public Property EditingControlDataGridView() As DataGridView Implements IDataGridViewEditingControl.EditingControlDataGridView
Get
Return dataGridViewControl
End Get
Set(ByVal value As DataGridView)
dataGridViewControl = value
End Set
End Property

Public Property EditingControlValueChanged() As Boolean Implements IDataGridViewEditingControl.EditingControlValueChanged
Get
Return valueIsChanged
End Get
Set(ByVal value As Boolean)
valueIsChanged = value
End Set
End Property

Public ReadOnly Property EditingControlCursor() As Cursor Implements IDataGridViewEditingControl.EditingPanelCursor
Get
Return MyBase.Cursor
End Get
End Property

Protected Overrides Sub OnTextChanged(ByVal eventargs As EventArgs)
valueIsChanged = True
Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
MyBase.OnTextChanged(eventargs)
End Sub

Protected Overrides Sub OnValidated(ByVal eventargs As EventArgs)
MyBase.Items.Add(MyBase.Text)
MyBase.OnValidated(eventargs)
End Sub

End Class

-----------------------------------------

Thanks to anyone that could assist! Thumbs Up | :thumbsup: Smile | :)
Questionhow can I built Hyperterminal functionality in vb.net Pin
Amanjot2-Dec-09 13:38
Amanjot2-Dec-09 13:38 
AnswerRe: how can I built Hyperterminal functionality in vb.net Pin
Dave Kreskowiak4-Dec-09 6:57
mveDave Kreskowiak4-Dec-09 6:57 
QuestionBouncing Ball Pin
rbjanaki2-Dec-09 12:57
rbjanaki2-Dec-09 12:57 
AnswerRe: Bouncing Ball Pin
Luc Pattyn2-Dec-09 13:13
sitebuilderLuc Pattyn2-Dec-09 13:13 
QuestionUninstalling a program Pin
RyJaBy2-Dec-09 7:04
RyJaBy2-Dec-09 7:04 
AnswerRe: Uninstalling a program Pin
The Man from U.N.C.L.E.2-Dec-09 7:34
The Man from U.N.C.L.E.2-Dec-09 7:34 
GeneralRe: Uninstalling a program Pin
RyJaBy4-Dec-09 6:38
RyJaBy4-Dec-09 6:38 
GeneralRe: Uninstalling a program Pin
Dave Kreskowiak4-Dec-09 6:57
mveDave Kreskowiak4-Dec-09 6:57 
GeneralRe: Uninstalling a program Pin
RyJaBy7-Dec-09 9:37
RyJaBy7-Dec-09 9:37 
GeneralRe: Uninstalling a program Pin
Dave Kreskowiak7-Dec-09 14:50
mveDave Kreskowiak7-Dec-09 14:50 
GeneralRe: Uninstalling a program Pin
RyJaBy9-Dec-09 7:30
RyJaBy9-Dec-09 7:30 
GeneralRe: Uninstalling a program Pin
Dave Kreskowiak9-Dec-09 15:02
mveDave Kreskowiak9-Dec-09 15:02 
QuestionNeed Code Pin
n0dy2-Dec-09 2:53
n0dy2-Dec-09 2:53 
AnswerRe: Need Code Pin
Eddy Vluggen2-Dec-09 3:23
professionalEddy Vluggen2-Dec-09 3:23 
AnswerRe: Need Code Pin
Tom Deketelaere2-Dec-09 3:25
professionalTom Deketelaere2-Dec-09 3:25 
AnswerRe: Need Code Pin
Dave Kreskowiak2-Dec-09 4:17
mveDave Kreskowiak2-Dec-09 4:17 
AnswerRe: Need Code Pin
Ashfield2-Dec-09 4:45
Ashfield2-Dec-09 4:45 

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.