none
Auto suggestion in DATAGRIDVIEW columns RRS feed

  • Question

  • HI 

    I m trying to enable auto suggestion in my datagridview column from database value but it does not work plz suggest

    here is my code

     Dim s As String = DataGridView1.Columns(4).HeaderText
            If s=("productname") Then
                Dim auto_texts As TextBox = e.Control
                If Not auto_texts Is Nothing Then
                    auto_texts.AutoCompleteMode = AutoCompleteMode.SuggestAppend
                    auto_texts.AutoCompleteSource = AutoCompleteSource.CustomSource
                    Dim coll As New AutoCompleteStringCollection()
                    auto_texts.AutoCompleteCustomSource = coll
                    con.Open()
                    Dim st As String = "select productname from MASTERPURCHASE "
                    Dim sda As New SqlDataAdapter(st, con)
                    Dim dt As New DataTable()
                    sda.Fill(dt)
                    For i As Integer = 0 To +DataGridView1.CurrentRow.Index
                        Dim name As String = dt.Rows(i)("productname").Value.ToString()
                        coll.Add(name)
                    Next
                    con.Close()
    
                End If
    
    
            End If
    

    Monday, October 8, 2018 6:30 PM

All replies

  • Hello,

    First thing is you should not be reading from the database each time you need auto-complete unless the data is changing often.

    Next up, you have not indicated where the code is e.g. EditingControlShowing is the proper place.

    The following is a proof of concept. Place a DataGridView on a form, add the following. AddItems procedure is hard coded where in your app it would be data from your SQL-Server database table.

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        DataGridView1.ColumnCount = 3
        DataGridView1.Columns(0).Name = "Product ID"
        DataGridView1.Columns(1).Name = "Product Name"
        DataGridView1.Columns(2).Name = "Product Price"
    
        Dim row As String() = New String() {"1", "Product 1", "1000"}
        DataGridView1.Rows.Add(row)
        row = New String() {"2", "Product 2", "2000"}
        DataGridView1.Rows.Add(row)
        row = New String() {"3", "Product 3", "3000"}
        DataGridView1.Rows.Add(row)
        row = New String() {"4", "Product 4", "4000"}
        DataGridView1.Rows.Add(row)
    
    End Sub
    Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
        Dim titleText As String = DataGridView1.Columns(1).HeaderText
        If titleText.Equals("Product Name") Then
            Dim autoText As TextBox = TryCast(e.Control, TextBox)
            If autoText IsNot Nothing Then
                autoText.AutoCompleteMode = AutoCompleteMode.Suggest
                autoText.AutoCompleteSource = AutoCompleteSource.CustomSource
                Dim DataCollection As New AutoCompleteStringCollection()
                addItems(DataCollection)
                autoText.AutoCompleteCustomSource = DataCollection
            End If
        End If
    End Sub
    Public Sub addItems(ByVal col As AutoCompleteStringCollection)
        col.Add("Product 1")
        col.Add("Product 2")
        col.Add("Product 3")
        col.Add("Product 4")
        col.Add("Product 5")
        col.Add("Product 6")
    End Sub
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, October 8, 2018 8:07 PM
    Moderator
  • Thanks for reply but your code works for limited data which we enter manually  but when i tried to pull values from database it does not works. 

    Please provide code to pull data from database in particular column (i.e. column(4)). from database

    Thanks once again

    Tuesday, October 9, 2018 3:39 AM
  • In regards to "please provide code", I don't have the time for that. If you want to learn this look at my code sample which has over 5,000 downloads that shows the logic to do this with both TextBox and ComboBox that will work doesn't show in a DataGridView but will work if you take time and learn from the code sample.

    Edit

    So I found a few minutes to take an existing code sample I did and add in code as shown in my former reply.

    Backend data class

    Imports System.Data.SqlClient
    
    Namespace Classes
        Public Class DataOperations
            Private ConnectionString As String =
                        "Data Source=KARENS-PC;" &
                        "Initial Catalog=ExampleDataGridViewComboBox_1;Integrated Security=True"
            Public Property PersonsTable As New DataTable
            Public Property ColorTable As New DataTable
            Public Property InformationTable As New DataTable
            Public Property Exception As New ErrorInformation
            ''' <summary>
            ''' Load data, called in form load event
            ''' </summary>
            Public Sub GetData()
                Using cn As New SqlConnection With {.ConnectionString = ConnectionString}
                    Using cmd As New SqlCommand With {.Connection = cn}
                        Try
                            cn.Open()
                        Catch ex As Exception
                            Exception.HasError = True
                            Exception.Message = ex.Message
                        End Try
    
                        cmd.CommandText = "SELECT ColorId,ColorText FROM Colors ORDER BY ColorText"
                        ColorTable.Load(cmd.ExecuteReader)
    
                        cmd.CommandText = "SELECT Id,[Text] FROM Information"
                        InformationTable.Load(cmd.ExecuteReader)
                        cmd.CommandText = "SELECT Id,ColorId ,FirstName FROM Person"
                        PersonsTable.Load(cmd.ExecuteReader)
    
                    End Using
                End Using
            End Sub
            ''' <summary>
            ''' Add a new color to the Colors Table if it does not
            ''' exists in the database table.
            ''' </summary>
            ''' <param name="pColor">Color to add</param>
            ''' <param name="pNewIdentifier">Contains the new primary key on success</param>
            ''' <returns></returns>
            Public Function InsertNewColor(pColor As Color, ByRef pNewIdentifier As Integer) As Boolean
    
                Using cn As New SqlConnection With {.ConnectionString = ConnectionString}
                    Using cmd As New SqlCommand With {.Connection = cn}
    
                        cmd.CommandText = "INSERT INTO dbo.Colors (ColorText) VALUES (@ColorText); " &
                                          "SELECT CAST(scope_identity() AS int);"
    
                        cmd.Parameters.AddWithValue("@ColorText", pColor.Name)
                        cn.Open()
    
                        Try
                            ' insert and get new id
                            pNewIdentifier = CInt(cmd.ExecuteScalar)
                            Return True
    
                        Catch ex As Exception
                            Exception.HasError = True
                            Exception.Message = ex.Message
                            Return False
                        End Try
                    End Using
                End Using
            End Function
            ''' <summary>
            ''' Called before above method to see if the color currently
            ''' exists in the database table.
            ''' </summary>
            ''' <param name="pColor"></param>
            ''' <returns></returns>
            Public Function ColorExists(pColor As Color) As Boolean
                Using cn As New SqlConnection With {.ConnectionString = ConnectionString}
                    Using cmd As New SqlCommand With {.Connection = cn}
    
                        cmd.CommandText = "SELECT [ColorId] FROM [dbo].[Colors] WHERE ColorText = @ColorText"
                        cmd.Parameters.AddWithValue("@ColorText", pColor.Name)
    
                        cn.Open()
    
                        Try
                            Dim reader As SqlDataReader = cmd.ExecuteReader
                            If reader.HasRows Then
                                Return True
                            Else
                                Return False
                            End If
                        Catch ex As Exception
                            Exception.HasError = True
                            Exception.Message = ex.Message
                            Return False
                        End Try
                    End Using
                End Using
    
            End Function
            ''' <summary>
            ''' Invoked from SelectionChangeCommitted in the form to update
            ''' any changes to the color in the DataGridViewComboBoxColumn of
            ''' the current row in the DataGridView.
            ''' </summary>
            ''' <param name="pPersonId"></param>
            ''' <param name="pColorId"></param>
            ''' <returns></returns>
            Public Function UpdateCurrentPerson(pPersonId As Integer, pColorId As Integer) As Boolean
    
                Dim result As Integer = 0
    
                Using cn As New SqlConnection With {.ConnectionString = ConnectionString}
                    Using cmd As New SqlCommand With {.Connection = cn}
                        cmd.CommandText = "UPDATE Person SET ColorId = @ColorId WHERE Id = @PersonId"
                        cmd.Parameters.AddWithValue("@ColorId", pColorId)
                        cmd.Parameters.AddWithValue("@PersonId", pPersonId)
    
                        Try
                            cn.Open()
                        Catch ex As Exception
                            Exception.HasError = True
                            Exception.Message = ex.Message
                        End Try
    
                        Try
                            result = cmd.ExecuteNonQuery
                        Catch ex As Exception
                            '
                            ' Decide how to deal with this
                            '
                            Console.WriteLine(ex.Message)
                        End Try
                    End Using
                End Using
    
                Return result = 1
    
            End Function
        End Class
    End Namespace

    Front end

    Public Class Form1
        WithEvents _bsPerson As New BindingSource
        WithEvents _bsComboBox As New BindingSource
        Private ReadOnly _bsColorInformation As New BindingSource
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim operation As New DataOperations
    
            operation.GetData()
    
            If Not operation.Exception.HasError Then
    
                DataGridView1.AutoGenerateColumns = False
                _bsComboBox.DataSource = operation.ColorTable
                _bsComboBox.Sort = "ColorText"
    
                ColorsColumn.DisplayMember = "ColorText"
                ColorsColumn.ValueMember = "ColorId"
                ColorsColumn.DataPropertyName = "ColorId"
                ColorsColumn.DataSource = _bsComboBox
                ColorsColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
    
                _bsPerson.DataSource = operation.PersonsTable
                DataGridView1.DataSource = _bsPerson
    
                _bsColorInformation.DataSource = operation.InformationTable
    
            End If
    
            For Each col In GetColors()
                cboColors.Items.Add(col.ToString())
            Next
    
            cboColors.SelectedIndex = 0
        End Sub
    
        ''' <summary>
        ''' Hook into changes while user is traversing items in the
        ''' DataGridViewComboBox column
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        Private Sub DataGridView1_EditingControlShowing(
            sender As Object,
            e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
    
            If DataGridView1.CurrentCell.IsComboBoxCell Then
                If DataGridView1.Columns(DataGridView1.CurrentCell.ColumnIndex).Name = "ColorsColumn" Then
                    Dim cb = TryCast(e.Control, ComboBox)
                    cb.DropDownStyle = ComboBoxStyle.Simple
                    cb.AutoCompleteMode = AutoCompleteMode.Suggest
    
                    cb.AutoCompleteSource = AutoCompleteSource.CustomSource
                    Dim dataCollection As New AutoCompleteStringCollection()
                    AddColors(dataCollection)
                    cb.AutoCompleteCustomSource = dataCollection
    
                    RemoveHandler cb.SelectionChangeCommitted, AddressOf _SelectionChangeCommittedForColorColumn
                    AddHandler cb.SelectionChangeCommitted, AddressOf _SelectionChangeCommittedForColorColumn
                End If
            End If
    
        End Sub
        Public Sub AddColors(ByVal col As AutoCompleteStringCollection)
            Dim ops As New DataOperations
            ops.GetData()
            Dim results = ops.ColorTable
    
            For Each row As DataRow In results.Rows
                col.Add(row.Field(Of String)("ColorText"))
            Next
        End Sub
        Private Sub _SelectionChangeCommittedForColorColumn(sender As Object, e As EventArgs)
            Dim colorId = CType(CType(sender, DataGridViewComboBoxEditingControl).SelectedItem, DataRowView).
                    Row.Field(Of Integer)("ColorId")
    
            UpdateTable(_bsPerson.Identifier, colorId)
    
        End Sub
        Private Sub UpdateTable(pPersonId As Integer, pColorId As Integer)
            Dim operation As New DataOperations
            operation.UpdateCurrentPerson(pPersonId, pColorId)
            If operation.Exception.HasError Then
                MessageBox.Show(operation.Exception.Message)
            End If
        End Sub
        ''' <summary>
        ''' This event attempts to add a new color to the Colors table
        ''' which is also the data source of the DataGridViewComboBoxColumn.
        ''' 
        ''' If ColorsExists returns true the record is not added as it would
        ''' be a duplicate, if ColorsExists returns false the color is added
        ''' and shows up in the DataGridViewComboBoxColumn immediately.
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim operations As New DataOperations
            Dim newColor As Color = Color.FromName(cboColors.Text)
            Dim newIdentifier As Integer = 0
    
            If Not operations.ColorExists(newColor) Then
                If operations.InsertNewColor(newColor, newIdentifier) Then
    
                    CType(_bsComboBox.DataSource, DataTable).Rows.
                        Add(New Object() {newIdentifier, newColor.Name})
    
                    MessageBox.Show($"The color {newColor.Name} has been added and ready now!")
    
                Else
                    If operations.Exception.HasError Then
                        MessageBox.Show(operations.Exception.Message)
                    End If
                End If
            Else
                MessageBox.Show($"The color {newColor.Name} not added as it exists already")
            End If
        End Sub
        Private Function GetColors() As IEnumerable(Of KnownColor)
            Dim systemColorsType As Type = GetType(SystemColors)
    
            Return (From kc In [Enum].GetValues(GetType(KnownColor)).Cast(Of KnownColor)()
                    Where kc <> KnownColor.Transparent AndAlso systemColorsType.GetProperty(kc.ToString()) Is Nothing
                    Select kc).ToArray()
    
        End Function
    End Class
    

    Helpers

    Namespace Classes
        Public Class ErrorInformation
            Public Property Message As String
            Public Property HasError As Boolean
        End Class
    End Namespace
    Namespace Extensions
        Module Extensions
            <DebuggerStepThrough()>
            <Runtime.CompilerServices.Extension()>
            Public Function IsComboBoxCell(ByVal sender As DataGridViewCell) As Boolean
                Dim result As Boolean = False
                If sender.EditType IsNot Nothing Then
                    If sender.EditType Is GetType(DataGridViewComboBoxEditingControl) Then
                        result = True
                    End If
                End If
                Return result
            End Function
    
            <DebuggerStepThrough()>
            <Runtime.CompilerServices.Extension()>
            Public Function Identifier(ByVal sender As BindingSource) As Integer
                Return CType(sender.Current, DataRowView).Row.Field(Of Integer)("Id")
            End Function
        End Module
    End Namespace
    Database script
    /****** 
    	* Before running this script ensure the path exists
    	* You should be able to run this script here inside of Visual Studio.
     ******/
    USE [master]
    GO
    
    CREATE DATABASE [ExampleDataGridViewComboBox_1]
     CONTAINMENT = NONE
     ON  PRIMARY 
    ( NAME = N'ExampleDataGridViewComboBox_1', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\ExampleDataGridViewComboBox_1.mdf' , SIZE = 4096KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
     LOG ON 
    ( NAME = N'ExampleDataGridViewComboBox_1_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\ExampleDataGridViewComboBox_1_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET COMPATIBILITY_LEVEL = 110
    GO
    IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
    begin
    EXEC [ExampleDataGridViewComboBox_1].[dbo].[sp_fulltext_database] @action = 'enable'
    end
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET ANSI_NULL_DEFAULT OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET ANSI_NULLS OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET ANSI_PADDING OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET ANSI_WARNINGS OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET ARITHABORT OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET AUTO_CLOSE OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET AUTO_CREATE_STATISTICS ON 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET AUTO_SHRINK OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET AUTO_UPDATE_STATISTICS ON 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET CURSOR_CLOSE_ON_COMMIT OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET CURSOR_DEFAULT  GLOBAL 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET CONCAT_NULL_YIELDS_NULL OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET NUMERIC_ROUNDABORT OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET QUOTED_IDENTIFIER OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET RECURSIVE_TRIGGERS OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET  DISABLE_BROKER 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET DATE_CORRELATION_OPTIMIZATION OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET TRUSTWORTHY OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET ALLOW_SNAPSHOT_ISOLATION OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET PARAMETERIZATION SIMPLE 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET READ_COMMITTED_SNAPSHOT OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET HONOR_BROKER_PRIORITY OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET RECOVERY FULL 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET  MULTI_USER 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET PAGE_VERIFY CHECKSUM  
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET DB_CHAINING OFF 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET TARGET_RECOVERY_TIME = 0 SECONDS 
    GO
    USE [ExampleDataGridViewComboBox_1]
    GO
    /****** Object:  Table [dbo].[Colors]    Script Date: 9/10/2016 5:35:31 AM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Colors](
    	[ColorId] [int] IDENTITY(1,1) NOT NULL,
    	[ColorText] [nvarchar](max) NULL,
     CONSTRAINT [PK_Colors] PRIMARY KEY CLUSTERED 
    (
    	[ColorId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    
    GO
    /****** Object:  Table [dbo].[Information]    Script Date: 9/10/2016 5:35:31 AM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Information](
    	[Id] [int] IDENTITY(1,1) NOT NULL,
    	[Text] [nvarchar](max) NULL,
     CONSTRAINT [PK_Information] PRIMARY KEY CLUSTERED 
    (
    	[Id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    
    GO
    /****** Object:  Table [dbo].[Person]    Script Date: 9/10/2016 5:35:31 AM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Person](
    	[Id] [int] IDENTITY(1,1) NOT NULL,
    	[ColorId] [int] NULL,
    	[FirstName] [nvarchar](max) NULL,
     CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED 
    (
    	[Id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    
    GO
    SET IDENTITY_INSERT [dbo].[Colors] ON 
    
    GO
    INSERT [dbo].[Colors] ([ColorId], [ColorText]) VALUES (1, N'Red')
    GO
    INSERT [dbo].[Colors] ([ColorId], [ColorText]) VALUES (2, N'Blue')
    GO
    INSERT [dbo].[Colors] ([ColorId], [ColorText]) VALUES (3, N'Green')
    GO
    INSERT [dbo].[Colors] ([ColorId], [ColorText]) VALUES (4, N'AntiqueWhite')
    GO
    INSERT [dbo].[Colors] ([ColorId], [ColorText]) VALUES (5, N'Brown')
    GO
    INSERT [dbo].[Colors] ([ColorId], [ColorText]) VALUES (6, N'DarkOrchid')
    GO
    INSERT [dbo].[Colors] ([ColorId], [ColorText]) VALUES (7, N'Black')
    GO
    SET IDENTITY_INSERT [dbo].[Colors] OFF
    GO
    SET IDENTITY_INSERT [dbo].[Information] ON 
    
    GO
    INSERT [dbo].[Information] ([Id], [Text]) VALUES (1, N'You must had picked red')
    GO
    INSERT [dbo].[Information] ([Id], [Text]) VALUES (2, N'You must had picked blue')
    GO
    INSERT [dbo].[Information] ([Id], [Text]) VALUES (3, N'You must had picked green')
    GO
    INSERT [dbo].[Information] ([Id], [Text]) VALUES (4, N'You must had picked green Antique white')
    GO
    INSERT [dbo].[Information] ([Id], [Text]) VALUES (5, N'You must had picked brown')
    GO
    INSERT [dbo].[Information] ([Id], [Text]) VALUES (6, N'You must had picked  dark orchid')
    GO
    INSERT [dbo].[Information] ([Id], [Text]) VALUES (7, N'You must had picked black')
    GO
    SET IDENTITY_INSERT [dbo].[Information] OFF
    GO
    SET IDENTITY_INSERT [dbo].[Person] ON 
    
    GO
    INSERT [dbo].[Person] ([Id], [ColorId], [FirstName]) VALUES (1, 2, N'Mary')
    GO
    INSERT [dbo].[Person] ([Id], [ColorId], [FirstName]) VALUES (2, 4, N'Karen')
    GO
    INSERT [dbo].[Person] ([Id], [ColorId], [FirstName]) VALUES (3, 6, N'Anne')
    GO
    INSERT [dbo].[Person] ([Id], [ColorId], [FirstName]) VALUES (4, 2, N'John')
    GO
    SET IDENTITY_INSERT [dbo].[Person] OFF
    GO
    USE [master]
    GO
    ALTER DATABASE [ExampleDataGridViewComboBox_1] SET  READ_WRITE 
    GO
    



    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Tuesday, October 9, 2018 9:41 AM
    Moderator