Solved

datagridview

Posted on 2014-02-26
4
345 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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