Hi,
My application is in VS2008 coded in Vb.net
I have a datagridView on one of my form.This is filled from the database at the load event of the form.The datagridView also has a column of type DatagridViewComboboxcolumn.
This DatagridViewComboboxcolumn already has 4 values added to it in its collection during design time.My requirement is when the data is loaded in the datagridview, the corresponding record which is supposed to be loaded in DatagridViewComboboxcolumn should compare its value with the value of DatagridViewComboboxcolumn.And if the value matches than that value should get selected in DatagridViewComboboxcolumn.
The database will have the any of the 4 values that are already in DatagridViewComboboxcolumn.It just has to compare both values and select the matching value.
Below is my Code

query= "Select Record1,Record2,Record3 from TableName"
        cmd = New SqlCommand(query, connection)
        dr = cmd.ExecuteReader()
        If dr.HasRows Then
            While dr.Read()
                datagridView.rows.add(dr(0),dr(1),dr(2))
                              
            End While
        End If

dr(2) is supposed to compare the record with DatagridViewComboboxcolumn.
How can i compare it with the value of my DatagridViewComboboxcolumn of my datagridView
Please suggest.

Hi.

Here are some alternate steps on how you can do it.
1. databind your datagridview in design mode
2. edit the desired column to make it a combobox column and add the items
3. then on the formload you can try this code :

Dim ds as new Dataset
Dim da as new sqlclient.SqlDataAdapter
da.SelectCommand = new Sqlclient.SqlCommand("Select Record1,Record2,Record3 from TableName",connection)
da.Fill(ds,"TableName")

datagridview1.datasource = ds
datagridview1.datamember = "TableName"

that should fill the table and select the correct value from the combobox column.
so this is a way to go using data sets and data adapters.

hope it helps, or gave you an idea on how to tackle the issue.

hi,
i have tried that.
I first designed my datagridview and set one of the column in datagridview as DatagridViewComboboxcolumn.When im using Dataadapter method to fill my datagridview it is filling 4 columns.3 columns that are fetched from database and the one extra column that i designed in datagridview during design time.Also its not selecting value according to my requirement.
Where am i goin wrong ?Any suggestions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.