datagrid select not responding properly

mattijsstu

Member
Joined
Feb 19, 2013
Messages
15
Programming Experience
Beginner
hi, i have a problem in my program (code below). When i select a cell in my datagrid, it's value displays in the textbox2. this works however sometimes it does not change when i select another cell. Can some one help me please?
VB.NET:
Imports System.IOPublic Class Form1
    Dim result1 As Double
    Dim result2 As Double
    Dim result3 As Double
    Dim result4 As Double
    Dim result5 As Double
    Dim result6 As Double
    Dim result7 As Double
    Dim resultfromtextbox1 As Double
    Dim resultfromtextbox2 As Double
    Dim resultfromtextbox6 As Double
    Dim resultfromtextbox7 As Double
    Dim resultfromtextbox8 As Double


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Database_q_waardeDataSet.q_waarden_tbl' table. You can move, or remove it, as needed.
        Me.Q_waarden_tblTableAdapter.Fill(Me.Database_q_waardeDataSet.q_waarden_tbl)


    End Sub
    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick


        TextBox2.Text = DataGridView1.CurrentCell.Value
    End Sub






    Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Double.TryParse(TextBox1.Text, resultfromtextbox1)
        Double.TryParse(TextBox2.Text, resultfromtextbox2)
        Double.TryParse(TextBox6.Text, resultfromtextbox6)
        Double.TryParse(TextBox7.Text, resultfromtextbox7)
        Double.TryParse(TextBox8.Text, resultfromtextbox8)
        result1 = 2.718281828 ^ ((3 / 7) * (Math.Log(resultfromtextbox1) - Math.Log(57.7) - Math.Log(resultfromtextbox2)))
        result2 = 50 / (result1 ^ (2 / 3))
        result3 = 0.5357 * result1
        result6 = result3 + result1
        result4 = (result6 / 2) * (Math.Cos((resultfromtextbox7 * Math.PI) / 180))
        result5 = result4 + resultfromtextbox6
        result7 = result1 * resultfromtextbox8
        TextBox3.Text = result1
        TextBox4.Text = result2
        TextBox5.Text = result3
    End Sub


    Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim saveFileDialog1 As New SaveFileDialog()


        saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
        saveFileDialog1.FilterIndex = 2
        saveFileDialog1.RestoreDirectory = True


        If saveFileDialog1.ShowDialog() = DialogResult.OK Then
            'open a new file stream with your selected filename from the SaveDialog control
            Using myStream As New StreamWriter(saveFileDialog1.FileName)
                myStream.WriteLine("D=" & result1)
                myStream.WriteLine("n_max=" & result2)
                myStream.WriteLine("d=" & result3)
                myStream.WriteLine("hv=" & result4)
                myStream.WriteLine("V=" & result5)
                myStream.WriteLine("ht=" & result7)


                myStream.Close()
            End Using
            MsgBox("Created File " & saveFileDialog1.FileName)
        End If
    End Sub


   
End Class

thanks

EDIT: feel so stupid changed cellcontentclick to cellclick.....

still i would like to make all my results# moved to a database i made, can any one give me links to info about these kind of things ?
 
Hi,

Since you have created a Strongly Typed Dataset for your data source you can do two things to update your database:-

1) You can call YourDataTableAdapter.Update(YourDataSetName.YourTableName)

or

2) You can call TableAdapterManager.UpdateALL(YourDataSetName)

Hope that helps.

Cheers,

Ian
 
yes, i used this line of code :
VB.NET:
Database_dimensioneringTableAdapter.Update(Database_dimensionerenDataSet)
when i push a button. buth i can't find an easy explenation on how to puth result1 or result 2 and so on in the first colum of row 1 of the database.
 
Hi,

Sorry, I am not fully understanding what you are trying to do. From the code you have shown you currently have:-

1) 1 Dataset called Database_q_waardeDataSet
2) 1 Table called q_waarden_tbl
3) I am then assuming that the DataGridView's Datasource is then set to your table q_waarden_tbl?

So, knowing the above, I do not know where you get this from:-

VB.NET:
Database_dimensioneringTableAdapter.Update(Database_dimensionerenDataSet)

This also implies that your are using a TableAdapter to update a Dataset which is incorrect. You would use a TableAdapterManager to update a Dataset.

You then say:-

when i push a button. buth i can't find an easy explenation on how to puth result1 or result 2 and so on in the first colum of row 1 of the database.

Firstly, you must remember that a Database is basically a collection of Data Tables, amongst other things, so when you want to save information to a Database what you actually have to do is save data to a Table within your Database. So the question is do you have another Table in your Database to hold the information you want to save?

If not, then this is where you need to start. This can then be added to your Dataset in Visual Studio which you can then save information to and call the Update method or UpdateAll method on the correct DataAdapter.

I hope that helps.

Cheers,

Ian
 
thanks
i changed some stuf around and it seems to be working i did this differently:
VB.NET:
Me.Database_dimensioneringTableAdapter1.Insert(TextBox9.Text, resultfromtextbox1, resultfromtextbox7, result1, result3, 0, 0, 0, 0, result5, 0, 0, 0, 0, 0, result4, result7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        Database_dimensioneringTableAdapter.Update(Database_dimensionerenDataSet)
 
Back
Top