Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. vb.net datagrid combobox

vb.net datagrid combobox

Scheduled Pinned Locked Moved Visual Basic
csharpgraphicshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jake072
    wrote on last edited by
    #1

    I am trying to create an autocomplete combobox for a datagrid in vb.net. I have everything working, except that I cannot force the column to stop when a user presses TAB to enter the column. I need to allow the user to press tab, and then my datagridcolumn must gain focus, but I cannot figure out how :( Anyways, I've attached my code (It's based on some previous articles I have read). I can get the control to retain focus when TAB is pressed if I put a break-point in the OnEnter(ByVal e as System.EventArgs) of the NoKeyUpCombo Class, but not without that. Please help!!!! Jake DataGridComboBoxColumn: Option Strict Off Option Explicit On Imports Microsoft.VisualBasic Imports System Imports System.ComponentModel Imports System.Data Imports System.Data.Common Imports System.Data.OleDb Imports System.Drawing Imports System.Windows.Forms Namespace DataGridTextBoxCombo ' Step 1. Derive a custom column style from DataGridTextBoxColumn ' a) add a ComboBox member ' b) track when the combobox has focus in Enter and Leave events ' c) override Edit to allow the ComboBox to replace the TextBox ' d) override Commit to save the changed data Public Class DataGridComboBoxColumn Inherits DataGridTextBoxColumn Public WithEvents ColumnComboBox As NoKeyUpCombo Private _source As System.Windows.Forms.CurrencyManager Private _rowNum As Integer Private _isEditing As Boolean Public Shared _RowCount As Integer Public Sub New() _source = Nothing _isEditing = False _RowCount = -1 ColumnComboBox = New NoKeyUpCombo ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDown AddHandler ColumnComboBox.SelectionChangeCommitted, AddressOf ComboStartEditing End Sub 'New Private Sub HandleScroll(ByVal sender As Object, ByVal e As EventArgs) If ColumnComboBox.Visible Then ColumnComboBox.Hide() End If End Sub 'HandleScroll Private Sub ComboStartEditing(ByVal sender As Object, ByVal e As EventArgs) _isEditing = True MyBase.ColumnStartedEditing(sender) End Sub 'ComboMadeCurrent Private Sub CompletionCombo_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ColumnComboBox.Leave If _isEditing Or ColumnComboBox._isEditing Then SetColumnValueAtRow(_source, _rowNum, Colum

    J 1 Reply Last reply
    0
    • J jake072

      I am trying to create an autocomplete combobox for a datagrid in vb.net. I have everything working, except that I cannot force the column to stop when a user presses TAB to enter the column. I need to allow the user to press tab, and then my datagridcolumn must gain focus, but I cannot figure out how :( Anyways, I've attached my code (It's based on some previous articles I have read). I can get the control to retain focus when TAB is pressed if I put a break-point in the OnEnter(ByVal e as System.EventArgs) of the NoKeyUpCombo Class, but not without that. Please help!!!! Jake DataGridComboBoxColumn: Option Strict Off Option Explicit On Imports Microsoft.VisualBasic Imports System Imports System.ComponentModel Imports System.Data Imports System.Data.Common Imports System.Data.OleDb Imports System.Drawing Imports System.Windows.Forms Namespace DataGridTextBoxCombo ' Step 1. Derive a custom column style from DataGridTextBoxColumn ' a) add a ComboBox member ' b) track when the combobox has focus in Enter and Leave events ' c) override Edit to allow the ComboBox to replace the TextBox ' d) override Commit to save the changed data Public Class DataGridComboBoxColumn Inherits DataGridTextBoxColumn Public WithEvents ColumnComboBox As NoKeyUpCombo Private _source As System.Windows.Forms.CurrencyManager Private _rowNum As Integer Private _isEditing As Boolean Public Shared _RowCount As Integer Public Sub New() _source = Nothing _isEditing = False _RowCount = -1 ColumnComboBox = New NoKeyUpCombo ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDown AddHandler ColumnComboBox.SelectionChangeCommitted, AddressOf ComboStartEditing End Sub 'New Private Sub HandleScroll(ByVal sender As Object, ByVal e As EventArgs) If ColumnComboBox.Visible Then ColumnComboBox.Hide() End If End Sub 'HandleScroll Private Sub ComboStartEditing(ByVal sender As Object, ByVal e As EventArgs) _isEditing = True MyBase.ColumnStartedEditing(sender) End Sub 'ComboMadeCurrent Private Sub CompletionCombo_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ColumnComboBox.Leave If _isEditing Or ColumnComboBox._isEditing Then SetColumnValueAtRow(_source, _rowNum, Colum

      J Offline
      J Offline
      j45mw
      wrote on last edited by
      #2

      Create a class module and stick this code in it: Imports System Imports System.Data Imports System.Windows.Forms Imports System.Drawing Namespace ComboBoxCode Public Class DataGridComboBoxColumn Inherits DataGridTextBoxColumn Private _comboBox As DataGridComboBox Private _sorce As CurrencyManager Private _rowNumber As Integer Private _editing As Boolean Public Sub New(ByVal dataSource As DataView, _ ByVal displayMember As String, _ ByVal valueMember As String) _sorce = Nothing _editing = False _comboBox = New DataGridComboBox _comboBox.DropDownStyle = ComboBoxStyle.DropDownList _comboBox.Visible = False _comboBox.DataSource = dataSource _comboBox.DisplayMember = displayMember _comboBox.ValueMember = valueMember AddHandler _comboBox.Leave, AddressOf _comboBox_Leave AddHandler _comboBox.SelectionChangeCommitted, _ AddressOf _comboBox_SelectionChangeCommitted End Sub Public ReadOnly Property ComboBox() As DataGridComboBox Get Return _comboBox End Get End Property Private Sub _comboBox_Leave(ByVal sender As Object, _ ByVal e As EventArgs) If _editing Then _editing = False SetColumnValueAtRow(_sorce, _rowNumber, _ _comboBox.Text) Invalidate() End If _comboBox.Visible = False AddHandler DataGridTableStyle.DataGrid.Scroll, _ AddressOf DataGrid_Scroll End Sub Private Sub DataGrid_Scroll(ByVal sender As Object, _ ByVal e As EventArgs) If _comboBox.Visible Then _comboBox.Visible = False End If End Sub Private Sub _comboBox_SelectionChangeCommitted( _ ByVal sender As Object, ByVal e As EventArgs) _editing = True MyBase.ColumnStartedEditing(CType(sender, Control)) End Sub Protected Overrides Function GetMinimumHeight() As Integer Return _comboBox.PreferredHeight End Function Protected Overrides Sub SetDataGridInColumn( _ ByVal value As DataGrid) MyBase.SetDataGridInColumn(value) _comboBox.Parent = CType(v

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups