LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   appending data to a data grid VB.net (https://www.linuxquestions.org/questions/programming-9/appending-data-to-a-data-grid-vb-net-347613/)

mrobertson 07-27-2005 09:33 AM

Appending data to a datagrid
 
I am currently working on an application where I will need to progressively build a data grid. I have a text file that looks like this:

1006, 32.56, .1348, .0466
1007, 33.12, .1234, .9876

I am going to need to read each line one at a time. One the first time around 1006 needs to go into "its text box" and so on. From there I need to query based on line 1's data and print to datagrid. Then I need to read line two and clear 1006 from the text box and put in 1007 and so on and then query for this set of data and append it to the data grid at the end of the data from the first line.

Can anybody help me as to how this would be done?

mrobertson 07-28-2005 07:37 AM

appending data to a data grid VB.net
 
I am working on an application in which I am going to need to append data to a data grid. Basically, I am going to have a loop that will read a text box, query for info in text box, print to data grid, change info in text box, query and print again and so on. I will need the first set of data displayed, then the next set appended to the previous set at the end, etc, etc. Can anyone help me with how to do this?

ewaltd 07-28-2005 08:11 AM

Don't know that this has anything to do with linux dev but....


If you are using a dataset...

Create a dataview on the dataset.
Bind the dataview ( not the dataset ) to the grid.

Then when you want to add data to the grid...

Grab the dataview back from the grid's datasource.
Add the data to the dataview.
Re-bind the dataview to the grid.

If you are using a custom object ( i.e. collection )...

Bind the collection to the grid

Then when you want to add data to the grid....

Grab the collection back from the grid's datasource
Add the new item to the collection.
Re-bind the colleciton to the grid.

mrobertson 07-28-2005 08:15 AM

would you be able to give me some coding examples of how to do this. I have never dealt with a data view before nor heard of it. Some source code would be a great help.

mrobertson 07-28-2005 08:16 AM

I am coding in vb.net not a linux language

ewaltd 07-28-2005 08:52 AM

There are tons of examples on datagrids, datasets, and dataviews in MSDN and on the web.

Doing a google search for any/all of those things will bring you more hits than you can read.

mrobertson 07-28-2005 08:57 AM

I tried something like this and got an Ora - 01722: Invalid Name the second time through the loop on the bolded line.

Code:

Private Sub butReadFromtextfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butReadFromtextfile.Click
        Try
            Dim mLine As String
            Dim oFile As System.IO.File
            Dim oRead As System.IO.StreamReader
            oRead = oFile.OpenText("C:\Documents and Settings\alogue\Desktop\Coil PDI\PDI.txt")

            While oRead.Peek <> -1
                mLine = oRead.ReadLine()
                'Get and split line details
                Dim mControlInfo(4) As String                'Sets up the 3 elements on the current line
                mControlInfo = mLine.Split(",")              'Tab between the quotes - i used commas, much easier
                txtgradecode.AppendText(mControlInfo(0))
                txtwidth.AppendText(mControlInfo(1))
                txthbgauge.AppendText(mControlInfo(2))
                txttargetgauge.AppendText(mControlInfo(3))
                Dim coilpdi As String
                Dim CoilPDIRowCount As Integer
                Dim PDIDataset As New DataSet

                Dim myConnection As New OracleConnection("Data Source=DUF_TCM; User ID=PCC;Password=DUFERCO")

                myConnection.Open()
                'Queries for the rolls that match the specified pdi
                coilpdi = "Select * from tcm_planned_coil where process_status = 'PLN' and grade_code ='" + txtgradecode.Text + "' and width = '" + txtwidth.Text + "' and hot_band_gauge='" + txthbgauge.Text + "' and target_gauge='" + txttargetgauge.Text + "' order by schedule_number, sequence_number"

                Dim PDICommand As New OracleCommand(coilpdi, myConnection)
                Dim PDIAdapter As New OracleDataAdapter(PDICommand)

                'clears the dataset
                PDIDataset.Clear()

                'using the command object, open a data adapter
                PDIAdapter.SelectCommand = PDICommand

                'Fills the data adapter with the dataset
              PDIAdapter.Fill(PDIDataset, "Table2")

                With Me.dgQueryResults
                    .DataSource = PDIDataset 'display the data in the datagrid
                    .NavigateTo(0, -1) 'expand the datagrid one level
                    .NavigateTo(0, "Table2") 'expand the datagrid down to the child level to show query results
                    .ParentRowsVisible = False
                    .AllowSorting = True
                    .AllowNavigation = True
                    .AllowDrop = False
                    .ColumnHeadersVisible = True
                    .PreferredColumnWidth = 300 'Set in pixels
                    .TabStop = False
                    .Enabled = True
                    .Visible = True
                    .ReadOnly = True
                    .AlternatingBackColor = System.Drawing.Color.Bisque
                End With

                CoilPDIRowCount = PDIDataset.Tables("Table2").Rows.Count

            End While

            oRead.Close()
            AddCellFormattingColumnStyles(Me.dgQueryResults, New FormatCellEventHandler(AddressOf FormatGridCells)) ' This is a private Sub within this class.
            myConnection.Close()


        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information)
        Finally

        End Try
    End Sub

Does this look like it will append data or just write over the first set? I have google appending data to a datagrid and data views alot and havent found any useful ino yet.


All times are GMT -5. The time now is 11:01 PM.