Solved

multiple datagridviews on a single form - problems

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

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'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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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