Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridViewComboBoxColumn trying to populate every 3rd row with ds

Status
Not open for further replies.

annarene

Programmer
Jul 7, 2008
17
US
Hello: this is my first window client server app in .net and have been assigned to create a form that contains a datagridview.

I decided to leave it unbound, because I need it to populate in a slightly unconventional way.
I also created each column and set them as drop-downs in the designer.

I need to populate every 3rd row (not column) with a list of colors values (pulled from my access db).
the row after this will always need to populate with a list of brightness values (also pulled from my access db).

Also, when the form loads, I create a specified set of rows. There will always be a given amount of rows and columns..the user cannot add or remove...just edit.

Here's my code thus far:
Code:
 Private Sub LoadDataGrid_New()
        ' Create an unbound DataGridView by declaring a column count.
        Dim Row0 As String = ""
        Dim Row1 As String = ""

        'Dim Row0 As String() = {""}
        'Dim Row1 As String() = {""}
        ''Dim Row2 As String() = {""}

        With Me.DataGridView1.Rows
            .Add(Row0)
            .Add(Row1)
            '.Add(Row2)
        End With

    End Sub

'After, I make a feeble attempt at populating the first row w/ colors

Code:
    Sub PopulateColorRow()

        Dim myDB As New OleDb.OleDbConnection(sConnectionString)
        Dim myDA As New OleDb.OleDbDataAdapter("Select ColorId,Color from tblColors order by Color", myDB)
        Dim myDS As New Data.DataSet
[COLOR="Green"]        Dim cbn As DataGridViewComboBoxColumn = DirectCast(DataGridView1.Columns(0), DataGridViewComboBoxColumn)[/COLOR]
        'Dim cbn1 As DataGridViewComboBoxColumn = DirectCast(Me.DataGridView1.Columns.Item(2), DataGridViewComboBoxColumn)


        'DataGridView1.Rows(0).Cells(0).Value = "COLOR"
        'DataGridView1.Rows(1).Cells(0).Value = "BRIGHTNESS"

        myDA.Fill(myDS, "tblColors")

        With cbn
            .DataSource = myDS.Tables("tblColors")
            .DisplayMember = "Color"
            .ValueMember = "ColorId"
        End With

        myDB.Close()

    End Sub

I know this is not correct...and not sure how to tell it to populate the dropdowns every 3rd row with colors, and every row after with brightness..(for now, just trying to get it to work on the first row).

I sure appreciate any input at all.
Thank you,

annarene
 
are the rows static? Are they the same throughout the datagrid, or are they loaded with actual values?

Get your data from access into a dataset, then hand move the rows from one data table to the dataset.
You will need something like a counter that resets, or else a counter and checking the MOD 3 value to see if it's 0.
You will probably want functions for each of the "patterned" rows, that you pass the actual data to, which return a fresh datarow that you can add to the datagrid.

BTW, you were close on the color tag. It's just color green

-Sometimes the answer to your question is the hack that works
 
Or just [Green]Green /Green[/Green], [red]red /red[/red], [yellow]etc[/yellow] with brackets.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Yeah. Note: Don't use yellow. :)

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Qik3Coder: Thanks for your reply. I'm currently working on making it work w/ the info you provided.

just wanted to say thanks....

annarene
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top