-
1
- #1
Copy and paste this code on a form with a datagrid:"dg".
It has no errors so I am not sure why the columns does not display. If you can help me I would love it.
Public Class DataGridComboBoxColumn
Inherits DataGridTextBoxColumn
Public MyCombo As DataGridComboBox
Private m_isEditing As Boolean
Public Sub New()
MyBase.New()
MyCombo = New DataGridComboBox
m_isEditing = False
AddHandler MyCombo.Leave, New _
EventHandler(AddressOf LeaveComboBox)
AddHandler MyCombo.SelectionChangeCommitted, New _
EventHandler(AddressOf OnSelectionChangeCommitted)
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)
MyCombo.Parent = Me.TextBox.Parent
MyCombo.Location = Me.TextBox.Location
MyCombo.Size = New Size(Me.TextBox.Size.Width, _
MyCombo.Size.Height)
MyCombo.Text = Me.TextBox.Text
Me.TextBox.Visible = False
MyCombo.Visible = True
MyCombo.BringToFront()
MyCombo.Focus()
End Sub
Private Sub LeaveComboBox(ByVal sender As _
Object, ByVal e As EventArgs)
MyCombo.Hide()
End Sub
Protected Overloads Overrides Function Commit(ByVal _
dataSource As CurrencyManager, ByVal rowNum As _
Integer) As Boolean
If m_isEditing Then
m_isEditing = False
SetColumnValueAtRow(dataSource, rowNum, _
MyCombo.Text)
End If
Return True
End Function
Private Sub OnSelectionChangeCommitted(ByVal sender As _
Object, ByVal e As EventArgs)
m_isEditing = True
MyBase.ColumnStartedEditing(sender)
End Sub
End Class
Public Class DataGridComboBox
Inherits ComboBox
Private WM_KEYUP As Integer = &H101
Protected Overrides Sub WndProc(ByRef m _
As System.Windows.Forms.Message)
If m.Msg = WM_KEYUP Then
Return
End If
MyBase.WndProc(m)
End Sub
End Class
Public Class dgComboBoxColumn
Inherits DataGridTextBoxColumn
Public MyCombo As ComboBox
Public Sub New()
MyBase.New()
MyCombo = New ComboBox
AddHandler MyCombo.Leave, New EventHandler( _
AddressOf LeaveComboBox)
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)
MyCombo.Parent = Me.TextBox.Parent
MyCombo.Location = Me.TextBox.Location
MyCombo.Size = New Size(Me.TextBox.Size.Width, _
MyCombo.Size.Height)
MyCombo.Text = Me.TextBox.Text
Me.TextBox.Visible = False
MyCombo.Visible = True
MyCombo.BringToFront()
MyCombo.Focus()
End Sub
Private Sub LeaveComboBox(ByVal sender _
As Object, ByVal e As EventArgs)
MyCombo.Hide()
End Sub
End Class
Sub mytest()
Dim styles As New DataGridTableStyle
styles.MappingName = "Authors"
Dim colAuthor As New DataGridTextBoxColumn
colAuthor.MappingName = "Author"
colAuthor.HeaderText = "Author"
colAuthor.Width = 200
styles.GridColumnStyles.Add(colAuthor)
' Dim dg As New DataGrid
dg.TableStyles.Add(styles)
Dim colCombo As DataGridComboBoxColumn
colCombo = New DataGridComboBoxColumn
colCombo.MappingName = "Role"
colCombo.HeaderText = "Role"
colCombo.Width = 150
colCombo.MyCombo.Items.Clear()
colCombo.MyCombo.Items.Add("Test1")
colCombo.MyCombo.Items.Add("Test2")
colCombo.MyCombo.Items.Add("Test3")
colCombo.MyCombo.Items.Add("Test4")
colCombo.MyCombo.Items.Add("Test5")
colCombo.MyCombo.DropDownStyle = _
ComboBoxStyle.DropDownList
styles.GridColumnStyles.Add(colCombo)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mytest()
End Sub
...and I'm out. O-BOY.
It has no errors so I am not sure why the columns does not display. If you can help me I would love it.
Public Class DataGridComboBoxColumn
Inherits DataGridTextBoxColumn
Public MyCombo As DataGridComboBox
Private m_isEditing As Boolean
Public Sub New()
MyBase.New()
MyCombo = New DataGridComboBox
m_isEditing = False
AddHandler MyCombo.Leave, New _
EventHandler(AddressOf LeaveComboBox)
AddHandler MyCombo.SelectionChangeCommitted, New _
EventHandler(AddressOf OnSelectionChangeCommitted)
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)
MyCombo.Parent = Me.TextBox.Parent
MyCombo.Location = Me.TextBox.Location
MyCombo.Size = New Size(Me.TextBox.Size.Width, _
MyCombo.Size.Height)
MyCombo.Text = Me.TextBox.Text
Me.TextBox.Visible = False
MyCombo.Visible = True
MyCombo.BringToFront()
MyCombo.Focus()
End Sub
Private Sub LeaveComboBox(ByVal sender As _
Object, ByVal e As EventArgs)
MyCombo.Hide()
End Sub
Protected Overloads Overrides Function Commit(ByVal _
dataSource As CurrencyManager, ByVal rowNum As _
Integer) As Boolean
If m_isEditing Then
m_isEditing = False
SetColumnValueAtRow(dataSource, rowNum, _
MyCombo.Text)
End If
Return True
End Function
Private Sub OnSelectionChangeCommitted(ByVal sender As _
Object, ByVal e As EventArgs)
m_isEditing = True
MyBase.ColumnStartedEditing(sender)
End Sub
End Class
Public Class DataGridComboBox
Inherits ComboBox
Private WM_KEYUP As Integer = &H101
Protected Overrides Sub WndProc(ByRef m _
As System.Windows.Forms.Message)
If m.Msg = WM_KEYUP Then
Return
End If
MyBase.WndProc(m)
End Sub
End Class
Public Class dgComboBoxColumn
Inherits DataGridTextBoxColumn
Public MyCombo As ComboBox
Public Sub New()
MyBase.New()
MyCombo = New ComboBox
AddHandler MyCombo.Leave, New EventHandler( _
AddressOf LeaveComboBox)
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)
MyCombo.Parent = Me.TextBox.Parent
MyCombo.Location = Me.TextBox.Location
MyCombo.Size = New Size(Me.TextBox.Size.Width, _
MyCombo.Size.Height)
MyCombo.Text = Me.TextBox.Text
Me.TextBox.Visible = False
MyCombo.Visible = True
MyCombo.BringToFront()
MyCombo.Focus()
End Sub
Private Sub LeaveComboBox(ByVal sender _
As Object, ByVal e As EventArgs)
MyCombo.Hide()
End Sub
End Class
Sub mytest()
Dim styles As New DataGridTableStyle
styles.MappingName = "Authors"
Dim colAuthor As New DataGridTextBoxColumn
colAuthor.MappingName = "Author"
colAuthor.HeaderText = "Author"
colAuthor.Width = 200
styles.GridColumnStyles.Add(colAuthor)
' Dim dg As New DataGrid
dg.TableStyles.Add(styles)
Dim colCombo As DataGridComboBoxColumn
colCombo = New DataGridComboBoxColumn
colCombo.MappingName = "Role"
colCombo.HeaderText = "Role"
colCombo.Width = 150
colCombo.MyCombo.Items.Clear()
colCombo.MyCombo.Items.Add("Test1")
colCombo.MyCombo.Items.Add("Test2")
colCombo.MyCombo.Items.Add("Test3")
colCombo.MyCombo.Items.Add("Test4")
colCombo.MyCombo.Items.Add("Test5")
colCombo.MyCombo.DropDownStyle = _
ComboBoxStyle.DropDownList
styles.GridColumnStyles.Add(colCombo)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mytest()
End Sub
...and I'm out. O-BOY.