Click here to Skip to main content
14,984,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Hello All,

             i have a query regarding add rows dynamically in datagridview .I need to have a datagridview which contains 4 columns as follows:

Column headers : Test1 ,Test2, Test3, Test4 (Creation of columns  is also dynamic)

Test1 ,Test2 and Test3 are of type DataGridViewComboBoxColumn  and Test4 of type DataGridViewTextBoxColumn 


Example: Suppose i have 4 rows in datagridview everytime the 1 and last row(4) under Test1  should have combo box items same and 2nd and 3rd have same data 


Test1            Test2                            Test3                           Test4

items(1,2)      items(5,5)                      items(6,7)                   first
items(4,5)      items(5,5)                      items(6,7)                   first
items(4,5)      items(5,5)                      items(6,7)                   first
items(1,2)      items(5,5)                      items(6,7)                   first

Please help me in this regard.

Thanks & Regards,
Sampath


What I have tried:

'DataGridView1.Rows.Add()

'Dim cmb As New DataGridViewComboBoxColumn()
'Dim cmb1 As New DataGridViewComboBoxColumn()
'Dim cmb2 As New DataGridViewComboBoxColumn()
'Dim txtbox As New DataGridViewTextBoxColumn()
'Dim cmbOthers As New DataGridViewComboBoxColumn()

' For i = 0 To 3

'cmb.HeaderText = "Select Data"
'cmb.Name = "cmb"
'cmb.MaxDropDownItems = 4
'cmb.Items.Add("1/3")
'cmb.Items.Add("1/2")
'DataGridView1.Columns.Add(cmb)

'cmb1.HeaderText = "Select Data1"
'cmb1.Name = "cmb1"
'cmb1.MaxDropDownItems = 4
'cmb1.Items.Add("True")
'cmb1.Items.Add("False")
'DataGridView1.Columns.Add(cmb1)
Posted
Updated 17-Jul-16 22:01pm

1 solution

what do you want to achieve in this ? just to add columns dynamically?
though you can use these code to add columns and rows dynamically

VB
Dim cmb(2) As DataGridViewComboBoxColumn
Dim txt As New DataGridViewTextBoxColumn


With DataGridView1
    For i As Int16 = 0 To 2
        cmb(i) = New DataGridViewComboBoxColumn
        cmb(i).HeaderText = "Data" & i
        .Columns.Add(cmb(i))

    Next
    .Columns.Add(txt)
    For i As Int16 = 0 To 3
        .Rows.Add()
    Next
End With
   
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900