Results 1 to 2 of 2

Thread: txtBox to (datatable) DataGridView

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    14

    Exclamation txtBox to (datatable) DataGridView

    Hello guyz!!!!
    I am new at coding and i have a problem....I have tried sooooo many solutions....But NOTHING!!!!
    So, I have to forms: main form --> frmKyria , and form2.
    In frmKyria there is a DataGridView1 that is datatable(I don't know what exactly does the datatable, but i found that code in order to save the data).
    Now, that i want is to add the text from 4 textboxes in form2 to frmKyria DataGridView1 in 4 cells in a row!
    p.s. the DataGridView collumns are made programmatically!
    Main Form Code(frmKyria)
    Code:
    Imports System.Xml
    Imports System.IO
    Public Class frmKyria
        Private filePath As String = "save.xml" 'xml filepath
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Form3.Visible = True
        End Sub
    #Region " User Defined Function "
    
        Private Function CreateEmptyTable(ByVal TableName As String, ByVal ParamArray ColumnNames() As String) As Boolean
            Dim writer As New XmlTextWriter(filePath, System.Text.Encoding.UTF8)
    
            Try
                writer.WriteStartDocument(True)
                writer.Formatting = Formatting.Indented
                writer.Indentation = 2
                writer.WriteStartElement("Table")
                writer.WriteStartElement(TableName)
                For Each ColumnName As String In ColumnNames
                    writer.WriteStartElement(ColumnName)
                    writer.WriteString(String.Empty)
                    writer.WriteEndElement()
                Next
                writer.WriteEndElement()
                writer.WriteEndElement()
                writer.WriteEndDocument()
                writer.Close()
            Catch ex As Exception
                MsgBox("Cannot create new table.")
                Return False
            End Try
    
            Return True
        End Function
        Private Function FormatDgvMstUser(ByRef ObjDgv As DataGridView) As Boolean
    
            cArith.Name = "clmArith"
            cArith.HeaderText = "Άρ."
            cArith.Width = 49
            cArith.DataPropertyName = "clmArith"
            cArith.Visible = True
            cArith.ReadOnly = False
    
            cAFM.Name = "clmAFM"
            cAFM.HeaderText = "ΑΦΜ"
            cAFM.Width = 100
            cAFM.DataPropertyName = "clmAFM"
            cAFM.Visible = True
            cAFM.ReadOnly = False
    
            cOnoma.Name = "clmOnoma"
            cOnoma.HeaderText = "Όνομα Επιχείρησης"
            cOnoma.Width = 180
            cOnoma.DataPropertyName = "clmOnoma"
            cOnoma.Visible = True
            cOnoma.ReadOnly = False
    
            cPoso.Name = "clmPoso"
            cPoso.HeaderText = "Ποσό"
            cPoso.Width = 80
            cPoso.DataPropertyName = "clmPoso"
            cPoso.Visible = True
            cPoso.ReadOnly = False
    
            cImerominia.Name = "clmImerominia"
            cImerominia.HeaderText = "Ημερομηνία"
            cImerominia.Width = 190
            cImerominia.DataPropertyName = "clmImerominia"
            cImerominia.Visible = True
            cImerominia.ReadOnly = False
    
            Try
                ObjDgv.Columns.Clear()
                ObjDgv.Columns.AddRange(New DataGridViewColumn() {cArith, cAFM, cOnoma, cPoso, cImerominia})
            Catch ex As Exception
                MsgBox("Cannot format datagridview.")
                Return False
            End Try
    
            Return True
        End Function
    
    #End Region
        Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim xmlFile As XmlReader
    
    
            'if file doesn't exist, create the file with its default xml table
            If Not File.Exists(filePath) Then
                If Not Me.CreateEmptyTable("Apodeiksi", "clmArith", "clmAFM", "clmOnoma", "clmPoso", "clmImerominia") Then End
            End If
    
            'fill dataset with selected xml table
            xmlFile = XmlReader.Create(filePath, New XmlReaderSettings())
            ds.ReadXml(xmlFile)
            xmlFile.Close()
    
            'init datagridview
            Me.DataGridView1.DataSource = ds.Tables(0)
            If Not Me.FormatDgvMstUser(Me.DataGridView1) Then End
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    
    
            Me.DataGridView1.EndEdit()
            dt = Me.DataGridView1.DataSource
    
            Try
                dt.WriteXml(filePath)
                MsgBox("Data has been saved.")
            Catch ex As Exception
                MsgBox("Data cannot be saved.")
            End Try
        End Sub
    End Class
    Form 2 Code
    Code:
    Private Sub btnEisagwgiform2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEisagwgiform2.Click
            'elegxos an to AFM einai 9-psifio kai einai mono arithmoi to POSO kai to AFM 
            If IsNumeric(txtAFM.Text) = True Then
                If txtAFM.TextLength = 9 Then
                    If IsNumeric(txtPoso.Text) Then
                        synoloPoso = synoloPoso + txtPoso.Text
    
                        'Metritis gia tin arithmisi twn apodeiksewn
                        metritisApod = metritisApod + 1
    
                        'Kataxorisi kai dimiourgia stilwn kai kataxwrisi se pinakes gia euresi megaliterou
                        Here i want your HELP!!!!
                        pinakas_afm(metritisApod) = txtAFM.Text
                        pinakas_onoma(metritisApod) = txtOnoma.Text
                        pinakas_poso(metritisApod) = txtPoso.Text
    
                        'Eyresi sunolikou posou
                        frmKyria.txtbSynoloapodeiksewn.Text = synoloPoso
    
                        '
                        If (frmKyria.ProgressBar1.Value + txtPoso.Text) > frmKyria.ProgressBar1.Maximum Then
                            frmKyria.ProgressBar1.Value = frmKyria.ProgressBar1.Maximum
                        Else
                            frmKyria.ProgressBar1.Value = (frmKyria.ProgressBar1.Value + txtPoso.Text)
                        End If
                        '
                        '
                        Me.Close()
                    Else
                        MsgBox("ΠΑΡΑΚΑΛΩ ΕΙΣΑΓΕΤΕ ΠΟΣΟ", MsgBoxStyle.Information, "***ΠΡΟΣΟΧΗ***")
                    End If
                Else
                    MsgBox("ΠΑΡΑΚΑΛΩ ΜΟΝΟ 9-ΨΗΦΙΟΥΣ ΑΡΙΘΜΟΥΣ ΣΤΟ ΑΦΜ", MsgBoxStyle.Information, "***ΠΡΟΣΟΧΗ***")
                End If
            Else
                MsgBox("ΠΑΡΑΚΑΛΩ ΜΟΝΟ ΑΡΙΘΜΟΥΣ ΣΤΟ ΑΦΜ ΚΑΙ ΣΤΟ ΠΟΣΟ", MsgBoxStyle.Information, "***ΠΡΟΣΟΧΗ***")
            End If
        End Sub

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    14

    Re: txtBox to (datatable) DataGridView

    If you know another way to save,load,update the datagridview to xml just tell me the way i will code....
    maybe the code in main form(up) is problematicly and doesn't allow me to add a new row

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width