Taking Values

Hi

Ive been trying to figure out how to take a value from a cell in a datagrid that imports data from excel so that i can take the value perform a calculation and move it to another cell on another datagrid but i cant find a way to remove the value or move it can anyone help plz its urgent!

thx



Answer this question

Taking Values

  • Zwigby

    That did it thx alot
  • GRH65

    Friend WithEvents DT As DataTable

    Private Sub BtnLoadProfit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLoadProfit.Click

    Dim strCon As String = "C:\master 6.xls"

    Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"

    & "Data Source=" & strCon _

    & ";" & "Extended Properties=Excel 8.0;"

    Dim ConnProfit As OleDb.OleDbConnection = New OleDb.OleDbConnection(sConnectionString)

    Dim DaProfit As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter

    Dim DsProfit As DataSet = New DataSet

    Dim strselcom As New OleDbCommand("Select * from ProfitAnalysis", ConnProfit)

    DaProfit.SelectCommand = strselcom

    Try

    ConnProfit.Open()

    DaProfit.Fill(DsProfit)

    DgProfit.DataSource = DsProfit.Tables(0).DefaultView

    DT = DsProfit.Tables(0)

    Catch ex As Exception

    MsgBox(ex.Message)

    Finally

    ConnProfit.Close()

    End Try

    End Sub

    Private Sub DT_RowChanged(ByVal sender As Object, ByVal e As System.Data.DataRowChangeEventArgs) Handles DT.RowChanged

    End Sub

    My VB is a bit rusty so bare with me :)

    You declare your datatable Friend WithEvents then an option to bind to its event handlers becomes availible in Visual Studio.

    You can then do your calculations there



  • pathakn

    will try that out thx
  • larimore

    Private Sub BtnLoadProfit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLoadProfit.Click

    Dim strCon As String = "C:\master 6.xls"

    Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _

    & "Data Source=" & strCon _

    & ";" & "Extended Properties=Excel 8.0;"

    Dim ConnProfit As OleDb.OleDbConnection = New OleDb.OleDbConnection(sConnectionString)

    Dim DaProfit As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter

    Dim DsProfit As DataSet = New DataSet

    Dim strselcom As New OleDbCommand("Select * from ProfitAnalysis", ConnProfit)

    DaProfit.SelectCommand = strselcom

    Try

    ConnProfit.Open()

    DaProfit.Fill(DsProfit)

    DgProfit.DataSource = DsProfit.Tables(0).DefaultView

    Catch ex As Exception

    MsgBox(ex.Message)

    Finally

    ConnProfit.Close()

    End Try

    End Sub

    --------------------------------------

    Once the data has loaded i want to be able to have the user enter values into certain cells and when a button is pressed the new values must be taken out, used in a calculation and then inserted into corresponding cells in another spreadsheet on another grid


  • Brent Clements

    Not quite sure what you mean could you maybe post me some sample code

    thx


  • Amit Puri

    ok now how do i go about taking the values from the cells cause the code im using isnt working :

    Dim strVal As String

    strVal = EventArgs.item.cell(3).text

    -----------------------------------------------------


  • ZMAN!!

    Private Sub DT_RowChanged(ByVal sender As Object, ByVal e As System.Data.DataRowChangeEventArgs) Handles DT.RowChanged

    Dim DR As DataRow = e.Row

    Dim value As String = DR(1)

    End Sub

    In this example I've hooked into the rowchanged event, wich fires after a row in the datatable is changed. I then use the e.Row to fetch a cell value



  • Brian Gordon

    The purpose of the datagrid control is primairly for display purposes.

    If you want to manipulate the data, you should manipulate its datasource.

    Can you post some code, so I can see what you are trying to do



  • Ali D

    You can hook into the rowchanged events of your dataset. Then do your calculations and copy the result into another datagrid.



  • Taking Values