Solved

multiple datagridviews on a single form - problems

Posted on 2010-11-08
4
448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

632 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