Results 1 to 10 of 10

Thread: [RESOLVED] DGV error

  1. #1

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Resolved [RESOLVED] DGV error

    Hi All,

    I am getting an error when saving my data to a datatable

    "Input string was not in a correct format.Couldn't store <ClientID> in fnClientID Column. Expected type is Int32."

    I was able to get past the errors by setting the data types to string and discovered the Heading was being saved to my datatable. How do I avoid this?

    Code:
    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
            intGrpSize = n
    
            Create_ClientTable()
            
    
                For Each cell As DataGridViewCell In dgvClients.SelectedCells
                    MessageBox.Show(cell.Value.ToString)
                Next
    
                'dgvClients.DataSource = ClientTable
                For Each row As DataGridViewRow In Me.dgvClients.SelectedRows()
                 
                'Clientid is int32, clientname is string & fnprgcode id int32    
                _ClientTable.Rows.Add("ClientID", "ClientName", "fnPrgCode") 
                Next
            
            frmChildWindow.CreateSession()
            'Dim frm As New frmCaseNts
            'frm.ShowDialog()
            Me.Close()
        End Sub
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DGV error

    You appear to be trying to get the data from each row in your grid and adding that data to a new row in a DataTable, but that is not what you're actually doing. This line:
    vb.net Code:
    1. _ClientTable.Rows.Add("ClientID", "ClientName", "fnPrgCode")
    isn't getting anything from the grid. It's just going to add those literal strings to the DataTable over and over. You need to actually get the data values from the current grid row, which is contained in the 'row' variable. You need to specify which cell of the row you want and then get the Value property of that cell. You can do that by specifying the name of the column, which is presumably what those three strings are:
    vb.net Code:
    1. _ClientTable.Rows.Add(row.Cells("ClientID").Value, row.Cells("ClientName").Value, row.Cells("fnPrgCode").Value)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: DGV error

    OK, I am now getting one row saved to my datatable. Is there something else I should be doing for the DGV. It is getting the last record selected.

    Here is where I save to DataTable
    Code:
    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
            intGrpSize = n
    
            Create_ClientTable()
           
            For Each row As DataGridViewRow In Me.dgvClients.SelectedRows()
                _ClientTable.Rows.Add(row.Cells("ClientID").Value, row.Cells("Name").Value, row.Cells("Program").Value)
            Next
            
            frmChildWindow.CreateSession()
            Me.Close()
        End Sub
    Here is where I am loading a DGV on another form to show me the results
    Code:
    Private Sub Load_DGV()
            dataGridView1.DataSource = _ClientTable
            End Sub
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DGV error

    Do you have multiple selected rows in dgvClients?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: DGV error

    yes. I had it set in the designer but double checked and put it in the create code

    Code:
    Private Sub create_dgv()
            dgvClients.Dock = DockStyle.Fill
            'dgvClients.VirtualMode = True
            dgvClients.AutoGenerateColumns = False
            dgvClients.DataSource = dsProfile1.Enrollment
            dgvClients.MultiSelect = True
    
            Dim column As DataGridViewColumn = _
                New DataGridViewTextBoxColumn()
    
            'Checkbox column unbound
            column = New DataGridViewCheckBoxColumn()
            'column.DataPropertyName = ""
            column.Name = "Selected_Client"
    
            dgvClients.Columns.Add(column)
    
            'ClientID Column
            column = New DataGridViewTextBoxColumn()
            column.DataPropertyName = "fnClientId"
            column.Name = "ClientID"
            dgvClients.Columns.Add(column)
    
            'Name Column
            column = New DataGridViewTextBoxColumn()
            column.DataPropertyName = "client_name"
            column.Name = "Name"
            dgvClients.Columns.Add(column)
    
            'Program Column
            column = New DataGridViewTextBoxColumn()
            column.DataPropertyName = "fnPrgCode"
            column.Name = "Program"
            dgvClients.Columns.Add(column)
    
            'Name the Column Header
            dgvClients.Columns(1).HeaderText = "Client ID"
            dgvClients.Columns(2).HeaderText = "Name"
            dgvClients.Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
            dgvClients.Columns(3).HeaderText = "Program No"
    
            Controls.Add(dgvClients)
            Me.AutoSize = True
    
            dgvClients.Columns(0).ReadOnly = False
    
        End Sub
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DGV error

    But are there actually multiple rows selected? Have you debugged your code? Do that before posting here because it's easier for you to see what your code is doing than it is for us.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: DGV error

    I used this to verify that each column and each row was being considered. I selected 3 rows and I got 12 message boxes (4 columns per row county the check box which has a value of 1)

    Code:
    For Each cell As DataGridViewCell In dgvClients.SelectedCells
                    MessageBox.Show(cell.Value.ToString)
                Next
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DGV error

    But have you debugged the code you already have? Did it add the same number of rows to the DataTable as you have rows selected in the grid?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: DGV error

    I think it may not be.

    Right after sending my last reply I added a DGV directly under the one I make selections in and used the same code to fill it as I am on the other form.

    It only displays one record. Same results

    How can I do a row count on the ClientTable? Or, what other methods are there to verify the data?

    It does not have a dataset or a tableadapter so I am not sure how to do it.
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  10. #10

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Resolved Re: DGV error

    I found the problem. I will post my solution and WHAT I was doing wrong in the later AM and mark it resolved.

    As always, thanks for your help John.

    Hint: it was in the Private Sub dgvClients_CellContentClick event where I am also keeping count by the number of check boxes selected.
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

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