Solved

multiple datagridviews on a single form - problems

Posted on 2010-11-08
4
440 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

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

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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
A short film showing how OnPage and Connectwise integration works.

929 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

10 Experts available now in Live!

Get 1:1 Help Now