?
Solved

datagridview

Posted on 2014-02-26
4
Medium Priority
?
361 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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