Solved

datagridview

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now