Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 471
  • Last Modified:

Context menu in a datagrid

I have a datagrid that is bound to a table in db. this grid displays two items

OrderNumber    OrderDate
12345                3/21/06

I am trying to right click the item and bring up a context menu that gets the data from this item and Performs an action based upon the order number as a string.

I know how to highlight the row.

Dim hti As System.Windows.Forms.DataGrid.HitTestInfo
        hti = Me.DataGrid1.HitTest(e.X, e.Y)

and Get the item

DataGrid1.Item(DataGrid1.CurrentRowIndex, 0).ToString

I am having trouble putinng this all together. Does anyone have any ideas?

Thanks
0
earngreen
Asked:
earngreen
  • 3
1 Solution
 
Bob LearnedCommented:
What problems are you having?  Where are you stuck?

Bob
0
 
earngreenAuthor Commented:
I want to highlight the row that i am looking for and right click to get the order column as
a string then I want to take the string and place it in a sql statement for execution.

1. I am not sure how to associate the contextmenu with the datagrid right click.
2. How to get the string from the right click action.
0
 
Bob LearnedCommented:
Here is a sample form that should highlight what you need to know:

Imports System.Text

Public Class frmDataGrid
  Inherits System.Windows.Forms.Form

  Private Const FLD_NAME As String = "Name"
  Private Const FLD_BA As String = "Batting Average"
  Private Const FLD_SLG As String = "Slugging Percentage"
  Private Const FLD_OBA As String = "On Base Average"
  Private Const FLD_G As String = "Games"
  Private Const FLD_AB As String = "At Bats"
  Private Const FLD_R As String = "Runs"
  Private Const FLD_H As String = "Hits"
  Private Const FLD_1 As String = "Singles"
  Private Const FLD_2 As String = "Doubles"
  Private Const FLD_3 As String = "Triples"
  Private Const FLD_RBI As String = "Runs Batted In"
  Private Const FLD_BB As String = "Base On Balls"
  Private Const FLD_SO As String = "Strike Outs"
  Private Const FLD_SB As String = "Stolen Bases"
  Private Const FLD_CS As String = "Caught Stealing"
  Private Const FLD_E As String = "Errors"
  Private Const FLD_W As String = "Wins"
  Private Const FLD_L As String = "Losses"
  Private Const FLD_ERA As String = "Earned Run Average"
  Private Const FLD_IP As String = "Innings Pitched"
  Private Const FLD_HR As String = "Home Runs"

#Region " Windows Form Designer generated code "

  Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call

  End Sub

  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
      If Not (components Is Nothing) Then
        components.Dispose()
      End If
    End If
    MyBase.Dispose(disposing)
  End Sub

  'Required by the Windows Form Designer
  Private components As System.ComponentModel.IContainer

  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer.  
  'Do not modify it using the code editor.
  Private WithEvents Panel1 As System.Windows.Forms.Panel
  Private WithEvents lblTitle As System.Windows.Forms.Label
  Private WithEvents linkSource As System.Windows.Forms.LinkLabel
  Private WithEvents gridStatistics As System.Windows.Forms.DataGrid
  Private WithEvents groupStatistics As System.Windows.Forms.GroupBox
  Private WithEvents radioDisplayBatter As System.Windows.Forms.RadioButton
  Private WithEvents radioDisplayPitcher As System.Windows.Forms.RadioButton
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.gridStatistics = New System.Windows.Forms.DataGrid
    Me.Panel1 = New System.Windows.Forms.Panel
    Me.groupStatistics = New System.Windows.Forms.GroupBox
    Me.radioDisplayBatter = New System.Windows.Forms.RadioButton
    Me.radioDisplayPitcher = New System.Windows.Forms.RadioButton
    Me.linkSource = New System.Windows.Forms.LinkLabel
    Me.lblTitle = New System.Windows.Forms.Label
    CType(Me.gridStatistics, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.Panel1.SuspendLayout()
    Me.groupStatistics.SuspendLayout()
    Me.SuspendLayout()
    '
    'gridStatistics
    '
    Me.gridStatistics.DataMember = ""
    Me.gridStatistics.Dock = System.Windows.Forms.DockStyle.Fill
    Me.gridStatistics.HeaderForeColor = System.Drawing.SystemColors.ControlText
    Me.gridStatistics.Location = New System.Drawing.Point(0, 52)
    Me.gridStatistics.Name = "gridStatistics"
    Me.gridStatistics.Size = New System.Drawing.Size(764, 446)
    Me.gridStatistics.TabIndex = 0
    '
    'Panel1
    '
    Me.Panel1.BackColor = System.Drawing.Color.DodgerBlue
    Me.Panel1.Controls.Add(Me.groupStatistics)
    Me.Panel1.Controls.Add(Me.linkSource)
    Me.Panel1.Controls.Add(Me.lblTitle)
    Me.Panel1.Dock = System.Windows.Forms.DockStyle.Top
    Me.Panel1.Location = New System.Drawing.Point(0, 0)
    Me.Panel1.Name = "Panel1"
    Me.Panel1.Size = New System.Drawing.Size(764, 52)
    Me.Panel1.TabIndex = 1
    '
    'groupStatistics
    '
    Me.groupStatistics.BackColor = System.Drawing.Color.AliceBlue
    Me.groupStatistics.Controls.Add(Me.radioDisplayBatter)
    Me.groupStatistics.Controls.Add(Me.radioDisplayPitcher)
    Me.groupStatistics.Location = New System.Drawing.Point(264, 4)
    Me.groupStatistics.Name = "groupStatistics"
    Me.groupStatistics.Size = New System.Drawing.Size(175, 45)
    Me.groupStatistics.TabIndex = 0
    Me.groupStatistics.TabStop = False
    Me.groupStatistics.Text = "St. Louis 2005 Stats"
    '
    'radioDisplayBatter
    '
    Me.radioDisplayBatter.Location = New System.Drawing.Point(108, 20)
    Me.radioDisplayBatter.Name = "radioDisplayBatter"
    Me.radioDisplayBatter.Size = New System.Drawing.Size(60, 17)
    Me.radioDisplayBatter.TabIndex = 1
    Me.radioDisplayBatter.TabStop = True
    Me.radioDisplayBatter.Text = "&Batters"
    '
    'radioDisplayPitcher
    '
    Me.radioDisplayPitcher.Location = New System.Drawing.Point(12, 20)
    Me.radioDisplayPitcher.Name = "radioDisplayPitcher"
    Me.radioDisplayPitcher.Size = New System.Drawing.Size(63, 17)
    Me.radioDisplayPitcher.TabIndex = 0
    Me.radioDisplayPitcher.TabStop = True
    Me.radioDisplayPitcher.Text = "&Pitchers"
    '
    'linkSource
    '
    Me.linkSource.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.linkSource.BackColor = System.Drawing.Color.AliceBlue
    Me.linkSource.Location = New System.Drawing.Point(604, 4)
    Me.linkSource.Name = "linkSource"
    Me.linkSource.Size = New System.Drawing.Size(152, 16)
    Me.linkSource.TabIndex = 1
    Me.linkSource.TabStop = True
    Me.linkSource.Text = "Statistics Source:  USA Today"
    '
    'lblTitle
    '
    Me.lblTitle.BackColor = System.Drawing.Color.AliceBlue
    Me.lblTitle.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Me.lblTitle.Location = New System.Drawing.Point(12, 4)
    Me.lblTitle.Name = "lblTitle"
    Me.lblTitle.Size = New System.Drawing.Size(196, 16)
    Me.lblTitle.TabIndex = 0
    Me.lblTitle.Text = "St. Louis Cardinals 2005 Statistics"
    '
    'frmDataGrid
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
    Me.ClientSize = New System.Drawing.Size(764, 498)
    Me.Controls.Add(Me.gridStatistics)
    Me.Controls.Add(Me.Panel1)
    Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Name = "frmDataGrid"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Data Grid Sample"
    CType(Me.gridStatistics, System.ComponentModel.ISupportInitialize).EndInit()
    Me.Panel1.ResumeLayout(False)
    Me.groupStatistics.ResumeLayout(False)
    Me.ResumeLayout(False)

  End Sub

#End Region

  Protected Overrides Sub Finalize()
    MyBase.Finalize()

    If Not m_graphics Is Nothing Then
      m_graphics.Dispose()
    End If
  End Sub  'Finalize

  Private m_tablePitchers As New DataTable
  Private m_tableBatters As New DataTable

  Private Sub linkSource_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles linkSource.LinkClicked
    Process.Start("http://www.usatoday.com/sports/baseball/nl/cardinals/stats05.htm")
  End Sub


  Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Create_StLouis_Pitchers_2005()
    Me.Create_StLouis_Batters_2005()
  End Sub  'Form_Load

  Private Sub Create_StLouis_Batters_2005()

    m_tableBatters.Columns.Add(FLD_NAME)
    m_tableBatters.Columns.Add(FLD_BA, GetType(Single))
    m_tableBatters.Columns.Add(FLD_SLG, GetType(Single))
    m_tableBatters.Columns.Add(FLD_OBA, GetType(Single))
    m_tableBatters.Columns.Add(FLD_G, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_AB, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_R, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_H, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_1, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_2, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_3, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_RBI, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_BB, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_SO, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_SB, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_CS, GetType(Integer))
    m_tableBatters.Columns.Add(FLD_E, GetType(Integer))

    Me.AddBatter("Pujols", 0.33, 0.609, 0.43, 161, 591, 129, 195, 360, 38, 2, 41, 117, 97, 65, 16, 2, 14)
    Me.AddBatter("Rodriguez", 0.295, 0.436, 0.382, 56, 149, 15, 44, 65, 6, 0, 5, 24, 19, 45, 2, 0, 2)
    Me.AddBatter("Eckstein", 0.294, 0.395, 0.363, 158, 630, 90, 185, 249, 26, 7, 8, 61, 58, 44, 11, 8, 15)
    Me.AddBatter("Grudzielanek", 0.294, 0.407, 0.334, 137, 528, 64, 155, 215, 30, 3, 8, 59, 26, 81, 8, 6, 7)
    Me.AddBatter("Walker", 0.289, 0.502, 0.384, 100, 315, 66, 91, 158, 20, 1, 15, 52, 41, 64, 2, 1, 2)
    Me.AddBatter("Taguchi", 0.288, 0.412, 0.322, 143, 396, 45, 114, 163, 21, 2, 8, 53, 20, 62, 11, 2, 2)
    Me.AddBatter("Nunez", 0.285, 0.361, 0.343, 139, 421, 64, 120, 152, 13, 2, 5, 44, 37, 63, 0, 1, 14)
    Me.AddBatter("Luna", 0.285, 0.409, 0.344, 64, 137, 26, 39, 56, 10, 2, 1, 18, 9, 25, 10, 2, 5)
    Me.AddBatter("Sanders", 0.271, 0.546, 0.34, 93, 295, 49, 80, 161, 14, 2, 21, 54, 28, 75, 14, 1, 2)
    Me.AddBatter("Gall", 0.27, 0.514, 0.282, 22, 37, 5, 10, 19, 3, 0, 2, 10, 1, 8, 0, 0, 0)
    Me.AddBatter("Edmonds", 0.263, 0.533, 0.385, 142, 467, 88, 123, 249, 37, 1, 29, 89, 91, 139, 5, 5, 2)
    Me.AddBatter("Molina", 0.252, 0.358, 0.295, 114, 385, 36, 97, 138, 15, 1, 8, 49, 23, 30, 2, 3, 7)
    Me.AddBatter("Schumaker", 0.25, 0.292, 0.308, 27, 24, 9, 6, 7, 1, 0, 0, 1, 2, 2, 1, 0, 0)
    Me.AddBatter("Mabry", 0.24, 0.407, 0.295, 112, 246, 26, 59, 100, 15, 1, 8, 32, 20, 63, 0, 0, 3)
    Me.AddBatter("Rolen", 0.235, 0.383, 0.323, 56, 196, 28, 46, 75, 12, 1, 5, 28, 25, 28, 1, 2, 6)
    Me.AddBatter("Seabol", 0.219, 0.295, 0.272, 59, 105, 11, 23, 31, 5, 0, 1, 10, 8, 23, 0, 0, 3)
    Me.AddBatter("Diaz", 0.208, 0.277, 0.248, 58, 130, 14, 27, 36, 6, 0, 1, 17, 5, 12, 0, 0, 1)
    Me.AddBatter("Duncan", 0.2, 0.6, 0.2, 9, 10, 2, 2, 6, 1, 0, 1, 3, 0, 5, 0, 0, 0)
    Me.AddBatter("Cedeno", 0.158, 0.175, 0.197, 37, 57, 4, 9, 10, 1, 0, 0, 8, 2, 6, 0, 2, 2)
    Me.AddBatter("Mahoney", 0.156, 0.219, 0.217, 26, 64, 5, 10, 14, 1, 0, 1, 6, 4, 10, 0, 0, 2)

  End Sub  'Create_StLouis_Batters_2005

  Private Sub Create_StLouis_Pitchers_2005()

    m_tablePitchers.Columns.Add(FLD_NAME)
    m_tablePitchers.Columns.Add(FLD_W, GetType(Integer))
    m_tablePitchers.Columns.Add(FLD_L, GetType(Integer))
    m_tablePitchers.Columns.Add(FLD_ERA, GetType(Single))
    m_tablePitchers.Columns.Add(FLD_BA, GetType(Single))
    m_tablePitchers.Columns.Add(FLD_G, GetType(Integer))
    m_tablePitchers.Columns.Add(FLD_IP, GetType(Integer))
    m_tablePitchers.Columns.Add(FLD_H, GetType(Integer))
    m_tablePitchers.Columns.Add(FLD_R, GetType(Integer))
    m_tablePitchers.Columns.Add(FLD_HR, GetType(Integer))
    m_tablePitchers.Columns.Add(FLD_BB, GetType(Integer))
    m_tablePitchers.Columns.Add(FLD_SO, GetType(Integer))

    m_tablePitchers.PrimaryKey = New DataColumn() {m_tablePitchers.Columns("Name")}

    Dim pitcher As New pitcher

    Me.AddPitcher("Johnson", 0, 0, 0.0, 0.3, 5, 2.2, 3, 0, 0, 3, 4)
    Me.AddPitcher("Isringhausen", 1, 2, 2.14, 0.202, 63, 59.0, 43, 14, 4, 27, 51)
    Me.AddPitcher("Al Reyes", 4, 2, 2.15, 0.177, 65, 62.2, 38, 15, 5, 20, 67)
    Me.AddPitcher("White", 0, 0, 2.16, 0.378, 6, 8.1, 14, 2, 1, 1, 1)
    Me.AddPitcher("Eldred", 1, 0, 2.19, 0.259, 31, 37.0, 35, 9, 3, 18, 29)
    Me.AddPitcher("An Reyes", 1, 1, 2.7, 0.133, 4, 13.1, 6, 4, 2, 4, 12)
    Me.AddPitcher("Carpenter", 21, 5, 2.83, 0.231, 33, 241.2, 204, 82, 18, 51, 213)
    Me.AddPitcher("Thompson", 4, 0, 2.95, 0.227, 40, 55.0, 46, 22, 5, 15, 29)
    Me.AddPitcher("King", 4, 4, 3.38, 0.293, 77, 40.0, 46, 17, 4, 16, 23)
    Me.AddPitcher("Tavarez", 2, 3, 3.43, 0.278, 74, 65.2, 68, 28, 6, 19, 47)
    Me.AddPitcher("Flores", 3, 1, 3.46, 0.24, 50, 41.2, 37, 22, 5, 13, 43)
    Me.AddPitcher("Suppan", 16, 10, 3.57, 0.275, 32, 194.1, 206, 93, 24, 63, 114)
    Me.AddPitcher("Mulder", 16, 8, 3.64, 0.273, 32, 205.0, 212, 90, 19, 70, 111)
    Me.AddPitcher("Morris", 14, 10, 4.11, 0.276, 31, 192.2, 209, 101, 22, 37, 117)
    Me.AddPitcher("Marquis", 13, 14, 4.13, 0.262, 33, 207.0, 206, 110, 29, 69, 100)
    Me.AddPitcher("Pulsipher", 0, 0, 6.75, 0.357, 5, 4.0, 5, 3, 0, 2, 1)
    Me.AddPitcher("Journell", 0, 1, 10.38, 0.333, 5, 4.1, 6, 6, 1, 5, 5)
    Me.AddPitcher("Cali", 0, 0, 10.5, 0.385, 6, 6.0, 10, 8, 3, 6, 5)
    Me.AddPitcher("Jarvis", 0, 1, 13.5, 0.25, 4, 3.1, 3, 5, 1, 3, 2)
    Me.AddPitcher("Wainwright", 0, 0, 13.5, 0.25, 2, 2.0, 2, 3, 1, 1, 0)

  End Sub  'Create_StLouis_Pitchers_2005

  Private Sub AddBatter(ByVal name As String, ByVal BA As Single, ByVal SLG As Single, ByVal OBA As Single, ByVal G As Integer, ByVal AB As Integer, ByVal R As Integer, ByVal H As Integer, ByVal _1B As Integer, ByVal _2B As Integer, ByVal _3B As Integer, ByVal HR As Integer, ByVal RBI As Integer, ByVal BB As Integer, ByVal SO As Integer, ByVal SB As Integer, ByVal CS As Integer, ByVal E As Integer)

    Dim row As DataRow = m_tableBatters.NewRow()

    row(FLD_NAME) = name
    row(FLD_BA) = BA
    row(FLD_SLG) = SLG
    row(FLD_OBA) = OBA
    row(FLD_G) = G
    row(FLD_AB) = AB
    row(FLD_R) = R
    row(FLD_H) = H
    row(FLD_1) = _1B
    row(FLD_2) = _2B
    row(FLD_3) = _3B
    row(FLD_RBI) = RBI
    row(FLD_BB) = BB
    row(FLD_SO) = SO
    row(FLD_SB) = SB
    row(FLD_CS) = CS
    row(FLD_E) = E

    m_tableBatters.Rows.Add(row)

  End Sub   'AddBatter


  Private Sub AddPitcher(ByVal name As String, ByVal w As Integer, ByVal l As Integer, ByVal era As Single, ByVal ba As Single, _
   ByVal g As Integer, ByVal ip As Integer, ByVal h As Integer, ByVal r As Integer, ByVal hr As Integer, ByVal bb As Integer, ByVal so As Integer)

    Dim row As DataRow = m_tablePitchers.NewRow()

    row(FLD_NAME) = name
    row(FLD_W) = w
    row(FLD_L) = l
    row(FLD_ERA) = era
    row(FLD_BA) = ba
    row(FLD_G) = g
    row(FLD_IP) = ip
    row(FLD_H) = h
    row(FLD_R) = r
    row(FLD_HR) = hr
    row(FLD_BB) = bb
    row(FLD_SO) = so

    m_tablePitchers.Rows.Add(row)

  End Sub  'AddPitcher

  Private Sub ApplyBatterStyle()

    Dim style As New DataGridTableStyle
    style.MappingName = m_tableBatters.TableName

    style.RowHeaderWidth = 15

    Me.SetColumnStyle(style, FLD_NAME, "Name")
    Me.SetColumnStyle(style, FLD_BA, "BA")
    Me.SetColumnStyle(style, FLD_SLG, "SLG")
    Me.SetColumnStyle(style, FLD_OBA, "OBA")
    Me.SetColumnStyle(style, FLD_G, "G")
    Me.SetColumnStyle(style, FLD_AB, "AB")
    Me.SetColumnStyle(style, FLD_R, "R")
    Me.SetColumnStyle(style, FLD_H, "H")
    Me.SetColumnStyle(style, FLD_1, "TB")
    Me.SetColumnStyle(style, FLD_2, "2B")
    Me.SetColumnStyle(style, FLD_3, "3B")
    Me.SetColumnStyle(style, FLD_RBI, "RBI")
    Me.SetColumnStyle(style, FLD_BB, "BB")
    Me.SetColumnStyle(style, FLD_SO, "SO")
    Me.SetColumnStyle(style, FLD_SB, "SB")
    Me.SetColumnStyle(style, FLD_CS, "CS")
    Me.SetColumnStyle(style, FLD_E, "E")

    Me.gridStatistics.TableStyles.Clear()
    Me.gridStatistics.TableStyles.Add(style)

    Me.AutoSizeColumns()

  End Sub  'ApplyBatterStyle

  Private Sub ApplyPitcherStyle()

    Dim style As New DataGridTableStyle
    style.MappingName = m_tablePitchers.TableName

    style.RowHeaderWidth = 15

    Me.SetColumnStyle(style, FLD_NAME, "Name")
    Me.SetColumnStyle(style, FLD_W, "W")
    Me.SetColumnStyle(style, FLD_L, "L")
    Me.SetColumnStyle(style, FLD_ERA, "ERA")
    Me.SetColumnStyle(style, FLD_BA, "BA")
    Me.SetColumnStyle(style, FLD_G, "G")
    Me.SetColumnStyle(style, FLD_IP, "IP")
    Me.SetColumnStyle(style, FLD_H, "H")
    Me.SetColumnStyle(style, FLD_R, "R")
    Me.SetColumnStyle(style, FLD_HR, "HR")
    Me.SetColumnStyle(style, FLD_BB, "BB")
    Me.SetColumnStyle(style, FLD_SO, "SO")

    Me.gridStatistics.TableStyles.Clear()
    Me.gridStatistics.TableStyles.Add(style)

    Me.AutoSizeColumns()

  End Sub   'ApplyPitcherStyle

  Private Sub AutoSizeColumns()

    Dim column As Integer
    Dim table As DataTable = CType(Me.gridStatistics.DataSource, DataTable)
    table.DefaultView.AllowNew = False

    Dim maxWidth(table.Columns.Count) As Integer
    For column = 1 To table.Columns.Count - 1
      For Each row As DataRow In table.Rows
        maxWidth(column) = Math.Max(maxWidth(column), TextWidth(row(table.Columns(column).ColumnName).ToString()))
      Next row
    Next column

    For column = 1 To table.Columns.Count - 1
      Dim style As DataGridTextBoxColumn = Me.gridStatistics.TableStyles(0).GridColumnStyles(column)
      style.Width = maxWidth(column)
    Next column

  End Sub  'AutoSizeColumns()

  Private Sub ShowStats(ByVal pointClick As Point)

    Dim hitTest As DataGrid.HitTestInfo = Me.gridStatistics.HitTest(pointClick)

    If Not hitTest Is Nothing Then
      Dim table As DataTable = CType(Me.gridStatistics.DataSource, DataTable)
      Dim row As DataRow = table.Rows(hitTest.Row)

      Dim builder As New StringBuilder
      For Each column As DataColumn In table.Columns
        builder.Append(column.ColumnName & ":  " & row(column.ColumnName).ToString() & vbCrLf)
      Next

      MessageBox.Show(builder.ToString())
    End If

  End Sub  'ShowStats

  Private m_graphics As Graphics = Nothing
  Private Function TextWidth(ByVal text As String) As Integer
    If m_graphics Is Nothing Then
      m_graphics = Me.CreateGraphics()
    End If

    Return m_graphics.MeasureString(text, Me.gridStatistics.Font).Width * 2
  End Function  'TextWidth

  Private Sub SetColumnStyle(ByVal style As DataGridTableStyle, ByVal name As String, ByVal title As String)

    Dim column As New DataGridTextBoxColumn

    column.HeaderText = title
    column.MappingName = name

    style.GridColumnStyles.Add(column)

  End Sub   'SetColumnStyle

  Private Sub Display_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radioDisplayPitcher.CheckedChanged, radioDisplayBatter.CheckedChanged

    If sender Is Me.radioDisplayBatter Then
      Me.gridStatistics.DataSource = m_tableBatters

      Me.ApplyBatterStyle()

    ElseIf sender Is Me.radioDisplayPitcher Then
      Me.gridStatistics.DataSource = m_tablePitchers

      Me.ApplyPitcherStyle()

    End If

  End Sub  'Display_CheckedChanged

  Private Sub gridStatistics_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gridStatistics.MouseDown
    If e.Button = MouseButtons.Right Then
      Me.ShowStats(New Point(e.X, e.Y))
    End If
  End Sub  'gridStatistics_MouseDown

End Class

Public Class Pitcher
  Public Name As String
  Public Wins As Integer
  Public Losses As Integer
  Public EarnedRunAverage As Single
  Public BattingAverage As Single
  Public Games As Integer
  Public InningsPitched As Single
  Public Hits As Integer
  Public Runs As Integer
  Public HomeRuns As Integer
  Public BaseOnBalls As Integer
  Public StrikeOuts As Integer
End Class

Public Class Batter
  Public Name As String
  Public BattingAverage As Single
  Public SluggingPercentage As Single
  Public OnBaseAverage As Single
  Public Games As Integer
  Public AtBats As Integer
  Public Runs As Integer
  Public Hits As Integer
  Public Singles As Integer
  Public Doubles As Integer
  Public Triples As Integer
  Public RunsBattedIn As Integer
  Public BaseOnBalls As Integer
  Public StrikeOuts As Integer
  Public StolenBases As Integer
  Public CaughtStealing As Integer
  Public Errors As Integer
End Class
0
 
Bob LearnedCommented:
Look closely at gridStatistics_MouseDown and ShowStats.

Bob
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now