Solved

multiple datagridviews on a single form - problems

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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