•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 425,895 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,915 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 838 | Replies: 2
![]() |
•
•
Join Date: Jan 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Hello: this is my first window 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 with a list of colors (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).
Here's my code thus far:
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.
After, I make a stab at populating the first row w/ colors:
It complains when after it completes this...it doesn't like the line I highlighted above in green....if I change the column index to 1, it's happy, but it doesn't put data in the first column . The main issue however, is that I need to know how to tell it to populate my dropdowns every 3rd row..(for now, just trying to get it to work on the first row).
I would sure appreciate any input at all.
thanks,
proctor
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 with a list of colors (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).
Here's my code thus far:
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.
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 SubAfter, I make a stab at populating the first row w/ colors:
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
Dim cbn As DataGridViewComboBoxColumn = DirectCast(DataGridView1.Columns(0), DataGridViewComboBoxColumn)
'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 SubIt complains when after it completes this...it doesn't like the line I highlighted above in green....if I change the column index to 1, it's happy, but it doesn't put data in the first column . The main issue however, is that I need to know how to tell it to populate my dropdowns every 3rd row..(for now, just trying to get it to work on the first row).
I would sure appreciate any input at all.
thanks,
proctor
•
•
Join Date: Jun 2008
Posts: 12
Reputation:
Rep Power: 1
Solved Threads: 0
Proctor, DataGridView doesn't allow to change type of Column once it defined.
you just try this code
DataGridView1.Columns.Remove(DataGridView1.Columns(0))
dim cbn as New DataGridViewComboBoxColumn
With cbn
.DataSource = myDS.Tables("tblColors")
.DisplayMember = "Color"
.ValueMember = "ColorId"
End With
DataGridView1.Columns.Insert(0, cbn)
Regards
Warun
you just try this code
DataGridView1.Columns.Remove(DataGridView1.Columns(0))
dim cbn as New DataGridViewComboBoxColumn
With cbn
.DataSource = myDS.Tables("tblColors")
.DisplayMember = "Color"
.ValueMember = "ColorId"
End With
DataGridView1.Columns.Insert(0, cbn)
Regards
Warun
Last edited by warun : Jul 8th, 2008 at 1:28 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the VB.NET Forum
- Previous Thread: A few problems with VB.NET!
- Next Thread: How to save unbound datagridview to access db


Linear Mode