Column Style

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way, without going to a 3rd party product, to make a column in a
datagrid a drop down list? Or to otherwise limit the users ability for entry
in a particular column to two or three possibilities (other than coded
validation after entry)?
 
Cor,

This slipped right in for me....thanks. But I'm getting some rather funky
behavior after I select. When the combo box loses focus, it has a tendency
to revert back to the first item, even after I have selected the second. Any
thoughts?
 
Ed,

Are you sure, I tried the sample again from my message and now Herfried
lives in Holland and Jay in Austria and they stay there.

Cor
 
EdB said:
Cor,

This slipped right in for me....thanks. But I'm getting some rather funky
behavior after I select. When the combo box loses focus, it has a
tendency
to revert back to the first item, even after I have selected the second.
Any
thoughts?

I use something very very similar based on George shepherd's FAQ,
When I used the code it had a problem.
Can't recall exactly what.
It was far too much trouble to try a different method or rewrite from
scratch so I tinkered a bit.
You can just cut and paste the code and see if your problem goes away.

=====================


Public Class DataGridComboBoxColumn
Inherits DataGridTextBoxColumn
' use the derived nokeyup combo to avoid tabbing problem
Public WithEvents ColumnComboBox As NoKeyUpCombo

Private WithEvents _source As CurrencyManager
Private _rowNum As Integer
Private _isEditing As Boolean

Shared Sub New()
'Warning: Implementation not found
End Sub
Public Sub New()
MyBase.New()

_source = Nothing
_isEditing = False


ColumnComboBox = New NoKeyUpCombo()
AddHandler ColumnComboBox.Leave, New EventHandler(AddressOf
LeaveComboBox)
AddHandler ColumnComboBox.SelectionChangeCommitted, New
EventHandler(AddressOf ComboStartEditing)

End Sub
Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager,
ByVal rowNum As Integer, ByVal bounds As Rectangle, ByVal readOnly1 As
Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
MyBase.Edit(source, rowNum, bounds, readOnly1, instantText,
cellIsVisible)
_rowNum = rowNum
_source = source
ColumnComboBox.Parent = Me.TextBox.Parent
ColumnComboBox.Location = Me.TextBox.Location
ColumnComboBox.Size = New Size(Me.TextBox.Size.Width,
ColumnComboBox.Size.Height)
ColumnComboBox.Text = Me.TextBox.Text
Me.TextBox.Visible = False
ColumnComboBox.Visible = True
ColumnComboBox.BringToFront()
ColumnComboBox.Focus()
End Sub
Protected Overloads Overrides Function Commit(ByVal dataSource As
CurrencyManager, ByVal rowNum As Integer) As Boolean

If _isEditing Then
_isEditing = False
SetColumnValueAtRow(dataSource, rowNum, ColumnComboBox.Text)
End If
Return True

End Function
Private Sub ComboStartEditing(ByVal sender As Object, ByVal e As
EventArgs)

_isEditing = True
MyBase.ColumnStartedEditing(sender)
End Sub
Private Sub LeaveComboBox(ByVal sender As Object, ByVal e As EventArgs)

If _isEditing Then
SetColumnValueAtRow(_source, _rowNum, ColumnComboBox.Text)
_isEditing = False
Invalidate()
End If
ColumnComboBox.Hide()

End Sub
End Class
 
Cor,

Cor Ligthert said:
Are you sure, I tried the sample again from my message and now Herfried
lives in Holland and Jay in Austria and they stay there.

LOL ;-).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top