Question Need some help with datagrids..

Most-Wanted

New member
Joined
Sep 19, 2010
Messages
3
Programming Experience
1-3
Okay, well first i would like to say hi to everyone here as i am new to the forums. I hope that you guys can be very helpful and help me with some of my problems. They all have to do with the data grids and i have been searching around for weeks now to find my problems. (It's probably something simple and i just can't get it)

My first question to you guys is that i have a data grid that stores raw values for Horsepower, Torque, and RPM. Now what happens is that these values need to be averaged (or smoothed) out a lot ( like 100 times ) to get usable data.

The code works by picking all the data in the grid and adding it to an array. It then goes through each row and averages the row before it with the current and row after it. Once it's done i put the new data back into the grid, but this is where i get an error. It says:

An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll

Additional information: DataTable already belongs to another DataSet.

The code is here:

VB.NET:
        'Add Data To Grid
        'Add New Data To Grid
        Dim ds As New DataSet
        ds.Reset()
        dt4.Reset()
        ds.Tables.Add(dt4) '<<-------This is the line that gets highlighted
        Dim dc1 As New DataColumn("HP")
        Dim dc2 As New DataColumn("TRQ")
        'Dim dc3 As New DataColumn("RPM")
        dt4.Columns.Add(dc1)
        dt4.Columns.Add(dc2)
        ' dt3.Columns.Add(dc3)
        For iq As Integer = 0 To FinalSmoothHP.Count - 1
            Dim dr As DataRow = dt4.NewRow
            dr("HP") = FinalSmoothHP.Item(iq)
            dr("TRQ") = FinalSmoothTQ.Item(iq)
            'dr("RPM") = FinalSmooth2.Item(i)
            dt4.Rows.Add(dr)
        Next
        DataGrid1.DataSource = Nothing
        DataGrid1.DataSource = dt4
        FinalSmoothHP.Clear()
        FinalSmoothTQ.Clear()

Hopefully you can help me with that problem! Thanks!

2nd Question:

Is there a way to use the data grid column names instead of having to use column numbers?

Example:

Instead of :
VB.NET:
 BRPMSmooth.Add(DataGrid1.Item(i2, 0))

How do i use the column name like:
VB.NET:
 BRPMSmooth.Add(DataGrid1.Item(i2, "RPM"))

See how i have to use 0 as the first column?
The reason why i ask is because the columns can be different every time and i would like to be able to identify the column names instead.

If you are still reading i hope you can help as this is my last resort and i can't find any kind of examples on this anywhere. Thank you so much!:D
 
Back
Top