Solved

datagridview

Posted on 2014-02-26
4
350 Views
Last Modified: 2014-05-01
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
Comment
Question by:javagair
  • 3
4 Comments
 

Author Comment

by:javagair
ID: 39889505
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
 

Author Comment

by:javagair
ID: 39889783
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39891837
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
 

Author Comment

by:javagair
ID: 39927789
will look at it.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question