Solved

How do I populate specific columns of a datagrid view from as list object

Posted on 2010-08-30
2
448 Views
Last Modified: 2012-05-10
Hello,

I know how to populate a datagridiew via a list object by setting its datasource to the list object as in
mydatagridview.datasource = mylist

However, I've now created a datagridview by adding the following columns at design time.  The name and Description columns are populated by the listobject. I want to allow the user to be able to enter data in the Sheet ID and to view details via the view details button located in the ViewDetails column of the datagridview.  
1. I'm not sure how to assign the name and description returned by list object to the correct column and how to permit the user to be able to make changes in a specific column of a datagrid view
Name
Description
SheetId
Export (checkbox)
ViewDetail (button)
0
Comment
Question by:chtullu135
2 Comments
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 33559946
you can reffer to a Cell value like this
1.Me.DatagridView.Rows(e.RowIndex).Cells("Name").FormattedValue
2.Me.DatagridView.Rows(e.RowIndex).Cells("Description").FormattedValue
Now about your button column try this

Private WithEvents frm as Form

Private Sub MyDataGridView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles MyDataGridView.CellClick

        Try

            Dim row As DataGridViewRow

            For Each row In Me.MyDataGridView.Rows

                If Not row.IsNewRow Then

                    If e.ColumnIndex >= 0 Then

                        If MyDataGridView.Columns(e.ColumnIndex).Name = _

                    "ButtonColumn" Then

                     If frm Is Nothing Then

                                frm = New DetailsForm

                                frm.StartPosition = FormStartPosition......

                                

                                frm.FormBorderStyle = Windows.Forms.FormBorderStyle.None

                                frm.Show()



                            End If

                            



                           End if

                    End If

                End If

            Next

        Catch ex As Exception

        End Try



    End Sub

Open in new window

0
 

Author Comment

by:chtullu135
ID: 33560026
Hello,
I kept at it and came up with this solution which seems to work.  However, I will be giving you credit for code you came up with.  It'll prove usefull and I thank you again for your help
Private Sub PopulateSelectTab()

        Dim retrievedTabList As New List(Of DatasetGroup)



        Try

            dgvDatasetGroups.DataSource = DataSetGroupDB.GetDatasetGroupList

            

            Dim buttons As New DataGridViewButtonColumn()

            With buttons

                .HeaderText = "ViewDetails"

                .Text = "ViewDetails"

                .Name = "Details"

                .UseColumnTextForButtonValue = True

                .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells

                .FlatStyle = FlatStyle.Standard



                .DisplayIndex = 0

            End With

            dgvDatasetGroups.Columns.Add(buttons)

            Dim checkboxes As New DataGridViewCheckBoxColumn

            With checkboxes

                .HeaderText = "Export"

                .Name = "Export"

                .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells

                .FlatStyle = FlatStyle.Standard

                .DisplayIndex = 1

            End With



            dgvDatasetGroups.Columns.Add(checkboxes)

            dgvDatasetGroups.Columns(0).Visible = False

            dgvDatasetGroups.Columns(4).Visible = False

            dgvDatasetGroups.Columns(5).Visible = False

            dgvDatasetGroups.Columns(6).Visible = False

            dgvDatasetGroups.Columns(0).ReadOnly = True

            dgvDatasetGroups.Columns(1).ReadOnly = True

            dgvDatasetGroups.Columns(2).ReadOnly = True

            dgvDatasetGroups.Columns(4).ReadOnly = True

            dgvDatasetGroups.Columns(5).ReadOnly = True

            dgvDatasetGroups.Columns(6).ReadOnly = True



        Catch ex As Exception

            MessageBox.Show(ex.Message, ex.GetType.ToString)

        End Try



    End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

21 Experts available now in Live!

Get 1:1 Help Now