Solved

multiple datagridviews on a single form - problems

Posted on 2010-11-08
4
445 Views
Last Modified: 2012-05-10
I need 3 datagridviews on a single form.  There are things that seem to be causing them to be entertwined.. For example..

    Private Sub dgRanktkn_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgMeritBadgetkn.CellFormatting, dgRanktkn.CellFormatting


        Dim setRow As WannalancitDataSet.ScoutAdvancementRankRow = _
        CType(CType(ScoutAdvancementRankBindingSource.List(e.RowIndex),  _
        DataRowView).Row(), WannalancitDataSet.ScoutAdvancementRankRow)

        If dgMeritBadgetkn.Columns(e.ColumnIndex).Name = "AwardDesc" Then
            sqlStr = "Select * from RankMBAwardCodes where AwardType = '" + setAwardType + "' and AwardCode = '" + setRow.AwardCode + "'"
            rdr = GetAdvancement(sqlStr)
            While rdr.Read
                e.Value = rdr("AwardDescription").ToString
            End While
        End If

If first & second grid have nothing, no errors. But if first grid has detail in a row, this second grid blows up with "Index 0 is either negitive or above rows count.

Before this I had an issue with the rows in grid 1 showing up on grid 2 & grid 3.. Figured out that although they all used the same table, I could not filter the table & move the filtered Dataset into the Grid.datasource. then refilter the same table and set those records into the next grids datasource.. Instead I had to have 3 seprate tables in my datasource all pointing to the same table, but to be used one each on each grid..
This got rid of all the grids being alike, but that's when I got this new error where all the datagrids seem to want to use the same System.Windows.Forms.DataGridViewCellFormattingEventArgs
0
Comment
Question by:moosetracker
  • 3
4 Comments
 
LVL 12

Expert Comment

by:rgn2121
ID: 34090072
I have a form with about 12-15 grids that are all separate as far as I know.  I don't really try any cell formatting, but I know that the grids each have their own copy of the data...DataSet.Tables(0).Copy  and they were all created in code and not with the designer.  Not sure if that helps or not...
0
 
LVL 1

Author Comment

by:moosetracker
ID: 34091764
Hmmm... Maybe the question is.. If you want to set or read information from a column on the grid, is there another way to do it besides using the cellformatingEventArgs?

To set an unbound field i use the cellformating as shown above..

For bound fields I also depend on the cellformattingEvent Args that is the e value of the event  like so as in this example of when the user does a click selection, I want to know what is in the fields in the selected row..

 Private Sub dgAwardTkn_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgAwardtkn.CellContentClick

        Dim setRow As WannalancitDataSet.ScoutAdvancementAwardRow = _
        CType(CType(ScoutAdvancementAwardBindingSource.List(e.RowIndex),  _
        DataRowView).Row(), WannalancitDataSet.ScoutAdvancementAwardRow)


        SelPersonID = setRow.PersonID
        SelFirstName = setRow.FirstName
        SelLastName = setRow.LastName
        SelAwardType = setRow.AwardType
        SelAwardCode = setRow.AwardCode
        SelDate = setRow.DateEarned

Is there another way to read and edit these grid columns not using this field???
0
 
LVL 1

Accepted Solution

by:
moosetracker earned 0 total points
ID: 34107572
I gound the answer..
To pick up information in a row during Cell formating it is :
Private Sub dgMeritBadgetkn_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgMeritBadgetkn.CellFormatting

Dim sqlStr As String = ""
Dim tmpAwardCode As String

'Pick up AwardCode so you can figure out & populate unbound column MeritBadge Description
tmpAwardCode = dgMeritBadgetkn(4, e.RowIndex).Value


If dgMeritBadgetkn.Columns(e.ColumnIndex).Name = "MeritBadgeDesc" Then
sqlStr = "Select * from RankMBAwardCodes where AwardType = '" + setAwardType + "' and AwardCode = '" + tmpAwardCode + "'"
rdr = GetAdvancement(sqlStr)
While rdr.Read
e.Value = rdr("AwardDescription").ToString
End While
End If


To find the data in a selected row it is:
Private Sub dgMeritBadgetkn_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgMeritBadgetkn.CellClick
Dim sqlStr As String = ""

SelPersonID = dgMeritBadgetkn(0, dgMeritBadgetkn.CurrentCell.RowIndex).Value ' col 0
SelFirstName = dgMeritBadgetkn(1, dgMeritBadgetkn.CurrentCell.RowIndex).Value ' col 1
SelLastName = dgMeritBadgetkn(2, dgMeritBadgetkn.CurrentCell.RowIndex).Value ' col 2
SelAwardType = dgMeritBadgetkn(3, dgMeritBadgetkn.CurrentCell.RowIndex).Value ' col 3
SelAwardCode = dgMeritBadgetkn(4, dgMeritBadgetkn.CurrentCell.RowIndex).Value ' col 4
'Col 5 is not a bound field, it is MB description
SelDate = dgMeritBadgetkn(6, dgMeritBadgetkn.CurrentCell.RowIndex).Value ' col 6
0
 
LVL 1

Author Closing Comment

by:moosetracker
ID: 34134726
Came up with the answer myself..
0

Featured Post

Independent Software Vendors: 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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 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