how to give column value to variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chocomon
    New Member
    • Feb 2012
    • 10

    how to give column value to variable

    how do i say that if you click any cell in a datagridview, then i want to assign a variable like 'a' the value of the 3rd column in the datagridview

    thanks
  • chocomon
    New Member
    • Feb 2012
    • 10

    #2
    its k i solved this problem

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      I have reset the answer because it's not really an answer. If you can, please post your solution and mark that as the answer.

      Comment

      • chocomon
        New Member
        • Feb 2012
        • 10

        #4
        ok sure~ sorry about the inconvenience.. ..
        first off, it turns out i needed the 2nd colunmn's value, not the 3rd and basically once i clicked a 'calculate' button, i wanted it to go into my datagridview and get all the values from the 2nd column and average them:
        Code:
         Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                Try
                    Me.MarksTableAdapter.FillBy2(Me.Database1DataSet21.Marks, txtSearch.Text)
                Catch ex As System.Exception
                    System.Windows.Forms.MessageBox.Show(ex.Message)
                End Try
                Button1.Visible = False
                    Dim h As Integer
                    h = DataGridView2.Columns(2).Index
                    Dim a As Integer
                    a = DataGridView2.Item(h, 0).Value
                    Dim b As Integer
                    b = DataGridView2.Item(h, 1).Value
                    Dim c As Integer
                    c = DataGridView2.Item(h, 2).Value
                    If DataGridView2.Rows(3).Index = False Then
                        Exit Sub
                    End If
                    Dim d As Integer
                d = DataGridView2.Item(h, 3).Value
                txtAverage.Text = (a + b + c + d) / (DataGridView2.RowCount - 1)
            End Sub
        Last edited by Rabbit; Feb 27 '12, 11:19 PM. Reason: Fixed code tags

        Comment

        Working...