• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

datagridview

I need to add an item to a combobox in a datagridview depending on who I am looking at.
there are currently 12 columns on the datagridview.
the 10th one is a combo box with four  choices.
depending on who is logged in there needs to be a fifth choice added to list.
I tried:
DataGridView1.Rows.Insert(9, New Object() {"Sick"})
don't seem to find any reference to column in literature on datagridview.  I am thinking I need to first call column 9 which would be 10, and then insert a new item at 4 which would be 5.

thanks

gary
0
javagair
Asked:
javagair
  • 3
1 Solution
 
javagairAuthor Commented:
also tried this code:
 If IsDBNull(DstSocSec.Tables(0).Rows(0).Item(7)) Then
                        Dim column As DataGridViewComboBoxColumn
                        column = New DataGridViewComboBoxColumn
                        column.DataPropertyName = "COMPTOREASON"
                        column.Name = "COMPTOREASON"

                        column.Items.AddRange("Bereavement", "Paid Holiday", "None")

                        Me.DataGridView1.Columns.Add(column)
                        DataGridView1.Columns("UOM").Width = 40

                    Else
                        If DstSocSec.Tables(0).Rows(0).Item(7) - DstSocSec.Tables(0).Rows(0).Item(8) > 0 Then
                            'DataGridView1.Rows.Insert(9, New Object() {"Sick"})
                            Dim column As DataGridViewComboBoxColumn
                            column = New DataGridViewComboBoxColumn
                            column.DataPropertyName = "COMPTOREASON"
                            column.Name = "COMPTOREASON"

                            column.Items.AddRange("Bereavement", "Paid Holiday", "None", "Sick")

                            Me.DataGridView1.Columns.Add(column)
                            DataGridView1.Columns("UOM").Width = 40
                        End If
the column already exists but has no items in it.

thanks

gary
0
 
javagairAuthor Commented:
the error message reads:
System.Argument Exception: Datagridview Combo box cell values is not valid

this occurs when reading back from my database, the words match in the database to those that I have in the combo on the datagrid
0
 
CodeCruiserCommented:
You can use the EditControlShowing event of grid to grab the combobox and add items to it

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.editingcontrolshowing(v=vs.110).aspx
0
 
javagairAuthor Commented:
will look at it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now