locked
populate an unbound column in bound datagridview using vb.net

    Question

  • I am populating a datagridview from a datatable and that is working fine.   I wish to add some calculated columns from data in the datatable.  At first, I did this by adding these to the table, but that makes it difficult to update the Access database.  These lines are commented out.  

    Right now, AWt and DOF are not working.   The values are there when I step through (lines 85-87), but the values are not put in the grid.   The value of NWt is placed in the grid as it should be.

    Lines 236 through 254 set up the new unbound columns.  85-87 should populate them.

    Public Class LotGrid
        Dim LotsTab As New DataTable
        Dim PurTab As New DataTable
        Dim SalTab As New DataTable
        Dim XFerTab As New DataTable
        Dim DeadTab As New DataTable
        Dim ExpTab As New DataTable
        Dim FrtTab As New DataTable
        Dim FutTab As New DataTable
        Dim PartTab As New DataTable
        Dim CalfTab As New DataTable
        Dim WeanTab As New DataTable
        Dim LotNo As String
        Dim Locat As String
        Dim StrComp = fGetStrComp()
        Dim CompConn As New OleDbConnection(StrComp)
        Dim LotsAdapter As New OleDbDataAdapter("SELECT * FROM Lots ORDER BY Lots.LotNo, Lots.Location;", CompConn)
        'Dim LotsDataSet As DataSet
    
    
        Private Sub LotGrid_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim i As Integer = 0
            'LotsDataSet = New DataSet
            'Dim DOFColumn As New DataColumn
            'Dim AWtColumn As New DataColumn
            Dim NWtColumn As New DataColumn
            Dim ShrinkColumn As New DataColumn
            Dim PcDdColumn As New DataColumn
            Dim emptyColumn As New DataColumn
            Dim DOF As Integer
            sReCalcAllLots()
            'LotsAdapter.Fill(LotsDataSet, "LotsTab")
            LotsAdapter.Fill(LotsTab)
            Try
                'With DOFColumn
                '    .DataType = System.Type.GetType("System.Int32")
                '    .ColumnName = "DOF"
                '    '.Expression = "DateDiff(DateInterval.Day, Today, AvgInDate)"
                'End With
    
                'With AWtColumn
                '    .DataType = System.Type.GetType("System.Double")
                '    .ColumnName = "AWt"
                '    .Expression = "IIf(HeadIn = 0, 0, PayWeight / HeadIn)"
                'End With
                With NWtColumn
                    .DataType = System.Type.GetType("System.Double")
                    .ColumnName = "NWt"
                    '.Expression = "PayWeight / HeadIn" '+ Dof*DailyGain"
                End With
                With PcDdColumn
                    .DataType = System.Type.GetType("System.Double")
                    .ColumnName = "PcDd"
                    .Expression = "IIf(HeadIn = 0, 0, Dead / HeadIn)"
    
                End With
                With ShrinkColumn
                    .DataType = System.Type.GetType("System.Double")
                    .ColumnName = "Shrink"
                    .Expression = "IIf(PayWeight = 0, 0, (PayWeight - InWeight) / PayWeight)"
                End With
                With emptyColumn
                    .DataType = System.Type.GetType("System.String")
                    .ColumnName = "Empty"
                    '.Expression = "''"
                End With
                With LotsTab.Columns
                    '.Add(DOFColumn)
                    '.Add(AWtColumn)
                    .Add(NWtColumn)
                    .Add(PcDdColumn)
                    .Add(ShrinkColumn)
                    .Add(emptyColumn)
                End With
                'Me.dgvLotData.DataSource = LotsDataSet.Tables("LotsTab").DefaultView
                dgvLotData.DataSource = LotsTab
                LotNo = dgvLotData.Rows(0).Cells("LotNo").Value
                Locat = dgvLotData.Rows(0).Cells("Location").Value
                sAdjustGrid()
                For Each r As DataGridViewRow In Me.dgvLotData.Rows
                    'Dim DOF As Integer = Today.Subtract(dgvLotData.Rows(i).Cells("AvgInDate").Value)
                    If dgvLotData.Rows(i).Cells("HeadIn").Value > 0 Then
    
                        DOF = DateDiff(DateInterval.Day, r.Cells("AvgInDate").Value, Today)
                        r.Cells("DOF").Value = DOF
                        r.Cells("AWt").Value = r.Cells("PayWeight").Value / r.Cells("HeadIn").Value
                        r.Cells("NWt").Value = r.Cells("PayWeight").Value / r.Cells("HeadIn").Value + DOF * r.Cells("DailyGain").Value
                        'r.Cells("PcDd").Value = r.Cells("Dead").Value / r.Cells("HeadIn").Value
                        'r.Cells("Shrink").Value = (r.Cells("PayWeight").Value - r.Cells("InWeight").Value) / r.Cells("PayWeight").Value
                    End If
                    i += 1
                Next
                sPurchaseGrid()
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
    
        End Sub
    
        Private Sub sAdjustGrid()
            Dim i As Integer
            Dim DOFColumn As New DataGridViewTextBoxColumn
            Dim AWtColumn As New DataGridViewTextBoxColumn
            Dim NWtColumn As New DataGridViewTextBoxColumn
            Dim ShrinkColumn As New DataGridViewTextBoxColumn
            Dim PcDdColumn As New DataGridViewTextBoxColumn
            Dim emptyColumn As New DataGridViewTextBoxColumn
            With dgvLotData
    
                .Columns("Location").Width = 110
                .Columns("PenPast").Width = 80
                .Columns("Current").HeaderText = "# Now"
                '.Columns("DOF").Width = 40
                '.Columns("DOF").DisplayIndex = 4
                '.Columns("DOF").DefaultCellStyle.Format = "n0"
                '.Columns("DOF").ReadOnly = True
                .Columns("Nwt").ReadOnly = True
                .Columns("NWt").Width = 46
                .Columns("NWt").DisplayIndex = 5
                .Columns("Nwt").HeaderText = "wt now"
                .Columns("Nwt").DefaultCellStyle.Format = "n0"
                .Columns("HeadIn").HeaderText = "# In"
                .Columns("PcDd").DisplayIndex = 10
                .Columns("PcDd").DefaultCellStyle.Format = "p2"
                .Columns("PcDd").Width = 50
                .Columns("PcDd").ReadOnly = True
                .Columns("Transfered").HeaderText = "Xferd"
                .Columns("Quality").Width = 110
                '.Columns("Quality").DefaultCellStyle = DataGridViewComboBoxColumn
                'Need to make Quality, Sex Feed From comboboxes
                .Columns("Sex").Width = 60
                '.Columns("Awt").HeaderText = "avg in"
                '.Columns("AWt").Width = 40
                '.Columns("AWt").DisplayIndex = 14
                '.Columns("AWt").DefaultCellStyle.Format = "n0"
                '.Columns("AWt").ReadOnly = True
                .Columns("Shrink").ReadOnly = True
                .Columns("Shrink").DisplayIndex = 15
                .Columns("Shrink").DefaultCellStyle.Format = "p2"
                .Columns("Shrink").Width = 50
                .Columns("Cost").Width = 70
                .Columns("Cost").DefaultCellStyle.Format = "c2"
                .Columns("Cost").ReadOnly = True
                .Columns("BookCost").ReadOnly = True
                .Columns("BookCost").DefaultCellStyle.Format = "c2" '17
                .Columns("BookCost").Width = 70
                .Columns("Sales").ReadOnly = True
                .Columns("Sales").Width = 70
                .Columns("Sales").DefaultCellStyle.Format = "c2"
                .Columns("Owned").DefaultCellStyle.Format = "p2"
                .Columns("Owned").HeaderText = "%Owned"
                .Columns("Owned").Width = 60
                .Columns("Bill Partners").Width = 60 '20
                .Columns("Bill Overhead").Width = 60
                .Columns("FeedTypeFrom").Width = 70
                .Columns("FeedTypeFrom").HeaderText = "Feed From"
                .Columns("Conversion").Width = 40
                .Columns("Conversion").HeaderText = "Conv"
                .Columns("DailyGain").HeaderText = "Day Gn"
                .Columns("DailyGain").Width = 40
                .Columns("EstMarketWeight").Width = 50
                .Columns("EstMarketWeight").HeaderText = "Est MktWt"
                .Columns("EstGainCost").HeaderText = "Est CostGn"
                .Columns("EstGainCost").Width = 60
                .Columns("EstBasis").Width = 50
                .Columns("Sales").Width = 70 '28
                .Columns("Sales").DefaultCellStyle.Format = "c2"
                .Columns("Sales").ReadOnly = True
                .Columns("Owned").DefaultCellStyle.Format = "p2"
                .Columns("OtherExpense").DefaultCellStyle.Format = "c2"
                .Columns("OtherExpense").Width = 70
                .Columns("FeedExpense").DefaultCellStyle.Format = "c2"
                .Columns("FeedExpense").Width = 70
                .Columns("MedExpense").Width = 70
                .Columns("MedExpense").DefaultCellStyle.Format = "c2"
                .Columns("IntExpense").DefaultCellStyle.Format = "c2"
                .Columns("IntExpense").Width = 70
                .Columns("AllocExpense").DefaultCellStyle.Format = "c2"
                .Columns("AllocExpense").Width = 70
                .Columns("Futures P/L").Width = 70
                .Columns("Futures P/L").DefaultCellStyle.Format = "c2"
                .Columns("AvgInDate").Width = 65
                .Columns("AvgInDate").DefaultCellStyle.Format = "d"
                .Columns("AvgInDate").HeaderText = "Avg Day In"
                .Columns("CurrentCont").Width = 50
                .Columns("CurrentCont").DefaultCellStyle.Format = "n0"
                .Columns("CurrentCont").HeaderText = "Fut Cont"
                .Columns("Sourc1").Width = 50
                .Columns("Sourc2").Width = 50
                .Columns("Sourc3").Width = 50
                .Columns("Sourc4").Width = 50
                .Columns("Comment").Width = 160
                .Columns("AcceptAllocation").Width = 60
                .Columns("Empty").DisplayIndex = 54
                .Columns("Empty").HeaderText = ""
                .Columns("Empty").Width = 30
                '.Columns("Empty").ReadOnly = True
                .Columns("Empty").MinimumWidth = 20
                '.Columns("Sourc4").Width = 60
                '.Columns("Origin").Visible = False 'need to drop from Lots
                '.Columns("Depreciation").Visible = False 'need to drop from Lots
    
                .Columns("PayWeight").Visible = False
                .Columns("InWeight").Visible = False
                .Columns("WeightSold").Visible = False
                .Columns("ChartAccounts").Visible = False
                .Columns("LbsFed").Visible = False
                .Columns("HeadDays").Visible = False
                .Columns("MarkToMarket$").Visible = False
                .Columns("MarkToMarketCost").Visible = False
                .Columns("ReconciledInt").Visible = False
                .Columns("OptInv").Visible = False
                .Columns("TempCont").Visible = False
                .Columns("EstDeadPer").Visible = False
                .Columns("AnimFact").Visible = False
                .Columns("DryCost").Visible = False
                .Columns("EstDOF").Visible = False 'need to drop estimated dof and compute also compute date fat and add as column
                .Columns("ValueMoYr").Visible = False
                For i = 0 To 7
                    If i < 2 Then
                        .Columns(i).DefaultCellStyle.BackColor = Color.DarkBlue
                        .Columns(i).DefaultCellStyle.ForeColor = Color.GhostWhite
                        .Columns(i).Frozen = True
                    End If
                    If i <> 2 Then
                        .Columns(i).ReadOnly = True
                        If i <> 0 Then .Columns(i).Width = 40
                    End If
    
                Next i
                For i = 26 To 39
                    .Columns(i).ReadOnly = True
                Next
                '.Rows(0).Frozen = True
            End With
            With DOFColumn
                .HeaderText = "DOF"
                .Name = "DOF"
                .Width = 40
                .DisplayIndex = 4
                .DefaultCellStyle.Format = "n0"
                .ReadOnly = True
            End With
            dgvLotData.Columns.Insert(4, DOFColumn)
    
            With AWtColumn
                .HeaderText = "avg in"
                .Name = "AWT"
                .Width = 40
                .DisplayIndex = 14
                .DefaultCellStyle.Format = "n0"
                .ReadOnly = True
            End With
            dgvLotData.Columns.Insert(14, AWtColumn)
        End Sub

    Wednesday, June 13, 2012 9:47 PM

All replies

  • Hi Jjob,

    Nice to see you.

    How about calculate it in a sql statement?

    For example, I assume you want to add the first column to the second column, so please try:

    Select column1,column2, column1+column2 as sumValue from your table

    This will be easy to add one more column in database.

    At last, I suggest you to make a short test code to reproduce your scenario. This just a suggestion.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 14, 2012 10:11 AM
    Moderator
  • Thanks.

    This might work.   My goal is to use SELECT * FROM Lots ORDER BY Lots.LotNo, Lots.Location and use a parallel update statement.  

    The database table I am addressing is very large and the Select line would be cumbersome.   I will do it that way if I can't just insert the columns in datagridview and populate them.  

    Thank you again.

    Friday, June 15, 2012 9:37 AM
  • What I am saying is that I would like to know what is wrong with the code I sent.   There is value to me to know the error, even if I end up having to do it your way.

    Thanks...

    Saturday, June 16, 2012 2:02 PM
  • Hi Jjob,

    Would you like to make your test code a little shorter? Include remove unrelated code, functions or subs.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 18, 2012 8:29 AM
    Moderator
  •  Private Sub LotGrid_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim i As Integer = 0
            Dim DOF As Integer
            LotsAdapter.Fill(LotsTab)
            Try
                dgvLotData.DataSource = LotsTab
                LotNo = dgvLotData.Rows(0).Cells("LotNo").Value
                Locat = dgvLotData.Rows(0).Cells("Location").Value
                sAdjustGrid()
                For Each r As DataGridViewRow In Me.dgvLotData.Rows
                    If dgvLotData.Rows(i).Cells("HeadIn").Value > 0 Then
    
                        DOF = DateDiff(DateInterval.Day, r.Cells("AvgInDate").Value, Today)
                        r.Cells("DOF").Value = DOF
                        r.Cells("AWt").Value = r.Cells("PayWeight").Value / r.Cells("HeadIn").Value
                    End If
                    i += 1
                Next
                
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
    
        End Sub
    
        Private Sub sAdjustGrid()
            
            Dim DOFColumn As New DataGridViewTextBoxColumn
            Dim AWtColumn As New DataGridViewTextBoxColumn
            
            
            With DOFColumn
                .HeaderText = "DOF"
                .Name = "DOF"
                .Width = 40
                .DisplayIndex = 4
                .DefaultCellStyle.Format = "n0"
                .ReadOnly = True
            End With
            dgvLotData.Columns.Insert(4, DOFColumn)
    
            With AWtColumn
                .HeaderText = "avg in"
                .Name = "AWT"
                .Width = 40
                .DisplayIndex = 14
                .DefaultCellStyle.Format = "n0"
                .ReadOnly = True
            End With
            dgvLotData.Columns.Insert(14, AWtColumn)
        End Sub
    I am sorry I left all of the comments in. I had thought they would show that it worked by putting the value into columns. I hope I didn't remove too much. Thanks for your help.
    Monday, June 18, 2012 12:38 PM
  • Okay, I built a new form that was simplified.   I noticed when I was building columns for the table, I put in

    AwtColumn.dataType = System.type.gettype("System.Double")

    When I added the column to DataGridView I used

    Dim AWtColumn as New DataGridViewTextBoxColumn

    Is the issue that, while I am setting the .DefaultCellSTyle.Format ="n0", I am not establishing that it has a system.double datatype?   I haven't found an example of how to do this, but I was wondering if this is the error.

    Monday, June 18, 2012 3:03 PM
  • I don't know what you're doing, but at least you should switch Option Strict On, fix the compile errors (by thoroughly deciding how to convert or cast), then post the code again. This gives more people the chance to help. (probably I can't).

    In this example, you're not using LotNo and Locat, right? Dunno if it's due to shortened code only.

    The DateDiff function is a bit moldy. Just use the "-" operator to subtract DateTime values and get a TimeSpan object of which you can retrieve all components. DateTime.Today is the shorter way to Today (more written in code but no additional call at runtime).

    Just "GetType(Double)" is safer and shorter.


    Armin

    Monday, June 18, 2012 10:32 PM
  • I shortened my code according to request by Mike Feng who is very helpful. 

    I don't understand your statement "Just "GetType(Double)" is safer and shorter."

    Monday, June 18, 2012 11:13 PM
  • I don't understand your statement "Just "GetType(Double)" is safer and shorter."

    GetType(Double) instead of  System.type.gettype("System.Double")

    Armin

    Monday, June 18, 2012 11:35 PM
  • Hi Jjob,

    I don't use your code since when I copy it to my project, I got some "variable is not defined" errors, and I made another sample to test this:

        Private Sub UnboundDatagridView_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Dim dt As New DataTable
            dt.Columns.Add(New DataColumn("c1", GetType(Integer)))
            dt.Columns.Add(New DataColumn("c2", GetType(Integer)))
    
            For i = 1 To 10
                dt.Rows.Add(i, i * 2)
            Next
    
            Me.DataGridView1.DataSource = dt
    
            For Each r As DataGridViewRow In DataGridView1.Rows
                r.Cells("Column1").Value = r.Cells("c1").Value + r.Cells("c2").Value
            Next
        End Sub

    And I get this result:

    As you can see, the first column Column1 is not bounded to a datasource.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 19, 2012 7:50 AM
    Moderator
  • Thanks.   I copied your code into my form and only c2 showed up on my datagridview.   No Column1 and no c1.   I think No Column1 because i did not

    Dim Column1 As New DataGridViewTextBoxColumn

    Column1.Naqme="Column1"

    dgvLotData.Columns.Insert(0, Column1)

    I don't know why c1 didn't show up.  

    I am still wondering if I need to define the datatype of Column1

    Tuesday, June 19, 2012 11:08 AM
  • Hi Jjob,

    To get the same result of mine, this is the designer code:

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class UnboundDatagridView
        Inherits System.Windows.Forms.Form
    
        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub
    
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
    
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Me.DataGridView1 = New System.Windows.Forms.DataGridView()
            Me.Column1 = New System.Windows.Forms.DataGridViewTextBoxColumn()
            CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'DataGridView1
            '
            Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
            Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.Column1})
            Me.DataGridView1.Location = New System.Drawing.Point(37, 50)
            Me.DataGridView1.Name = "DataGridView1"
            Me.DataGridView1.Size = New System.Drawing.Size(392, 303)
            Me.DataGridView1.TabIndex = 0
            '
            'Column1
            '
            Me.Column1.HeaderText = "Column1"
            Me.Column1.Name = "Column1"
            '
            'UnboundDatagridView
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(528, 429)
            Me.Controls.Add(Me.DataGridView1)
            Me.Name = "UnboundDatagridView"
            Me.Text = "UnboundDatagridView"
            CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
    
        End Sub
        Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
        Friend WithEvents Column1 As System.Windows.Forms.DataGridViewTextBoxColumn
    End Class
    

    So what you need to do is:

    Add a new form named UnboundDatagridView, and paste the designer code to the file UnboundDatagridView.designer.vb,

    And handler the form load event like my last post.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 19, 2012 11:39 AM
    Moderator
  • Okay, I copied your code exactly both into a new form UnboundDatagridView and the designer code to UnboundDatagridView.designer.vb.

    The result was the data was not put into Column1.   While I did not set up Column1 in my grid because I wanted it to be in the 4th column, I think the cause is probably the same.   I was setting up Column1 (or DOF) in code.

    I put the code beneath a try, but did not have an exception.   I set the value that went into r.Cells("Column1").Value to a string and it still did not work.

    I am convinced that if I can figure out why this is not working with your code, I can interpolate to my code.

    Thanks for your effort.

    Tuesday, June 19, 2012 7:07 PM
  • Hi Jjob,

    Would you like to test this project: http://sdrv.ms/NPOHXP ? And the document name is WinApp-ForJjob.zip

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Wednesday, June 20, 2012 5:04 AM
    Moderator
  • I have been receiving "There's a temporary problem with the service. Please try again. If you continue to get this message, try again later." since I received your suggestion.   I started a brand new project and it works as you describe.  

    What settings could be off in my current project that are keeping it from functioning?

    Thanks...

     
    • Edited by jjobcorp Wednesday, June 20, 2012 8:13 PM
    Wednesday, June 20, 2012 7:56 PM
  • Hi Jjob,

    When you run your current project, do you get any exception?

    Anyway, please try this:

    Import the working form from your brand new project into your current project, to check whether it works or not.

    You can achieve this by:

    1. right click on your current project.

    2. Click add and choose existing Item

    3. Browse to the working form in your brand new project.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 21, 2012 5:33 AM
    Moderator
  • Okay, it works fine.   I obviously have a setting wrong.  

    One option would be to move all of my programs to the new project, but I would love to know what I have wrong and there are a lot of programs.

    Thursday, June 21, 2012 11:38 AM
  • Hi Jjob,

    If so, the issue is not related to your project setting, just that form. Would you like to check what else do you have done in that form?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 22, 2012 3:23 AM
    Moderator
  • I think it is just the opposite.   Your form works on the new project, but not on my project.   There appears to be a project setting that is keeping Column1 from populating.  
    Friday, June 22, 2012 12:45 PM
  • I have made progress, but have not found the problem.   I removed all references from my project that were not on your project.   It did not help.

    I copied forms from my project to yours and then had the application start with my menu.   When I did this and then linked to the form UnboundDatagridView, the calculated column didn't work.   When the application starts with UnboundDatagridView, it works fine.   What could be causing this?

    Saturday, June 23, 2012 4:55 PM
  • Hi Jjob,

    Would you like to upload your project here?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 25, 2012 5:04 AM
    Moderator
  • Sure, how do I upload the whole project?

    Here is what I have found.   When I call the form by

      Dim NewMDIChild As New unboundDatagrdView
            NewMDIChild.MdiParent = Me
            NewMDIChild.Show()

    It will not calculate the columns.  
     when I load it as

            Dim myform As New unboundDatagrdView
            myform.Show()
        

    It works fine.

    I would love to upload the project and find out, but I don't see a place to upload the whole project.

    Wednesday, June 27, 2012 1:21 PM
  • Hi Jjob,

    I have reproduced this issue on my side based on your description.

    I found that when the form show in a MDI form, it will reset the datasource again. After the datasource is reset, the value you have populated has been cleaned. So you don't see the values in column column1.

    So I suggest you make the datagridview control is visible for MDI form and populated the column1 in MDI forum.

            Dim udgv As New UnboundDatagridView
            udgv.MdiParent = Me
            udgv.Show()
    
            For Each r As DataGridViewRow In udgv.DataGridView1.Rows
                r.Cells("Column1").Value = r.Cells("c1").Value + r.Cells("c2").Value
            Next

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Mike FengModerator Sunday, July 08, 2012 8:48 AM
    • Unmarked as answer by jjobcorp Monday, July 09, 2012 12:53 PM
    Thursday, June 28, 2012 5:55 AM
    Moderator
  • That works for this simple grid as did leaving the populating in UnboundDatagrdView and using the following

     Dim myform As New unboundDatagrdView
            myform.Show()

    What I am trying to do is open the bound datagridview in a NewMDIChild and populate it.   

    The code I am trying to use is much more complicated and the unbound columns are inserted into a bound grid.   It works with myform.show; however, if there are errors in the form that is not a child, it is harder to isolate them and step through the code and the form that is not a child also is more difficult to manage.   Is this a glitch in visual studio that they act diferently; or, is there a fix?

    Thursday, June 28, 2012 2:51 PM
  • Hi Jjob,

    If the logic is very complicated, you can make a function to implement it, and call this function in the MDI form.

            Dim udgv As New UnboundDatagridView
            udgv.MdiParent = Me
            udgv.Show()
    
            udgv.FillFunction()

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 29, 2012 5:09 AM
    Moderator
  • Hi Jjob,

    Do you have any update?

    I have marked my reply as answer, if you have any concerns about this, please feel free to unmarked and follow up.

    Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Sunday, July 08, 2012 8:49 AM
    Moderator
  • I unmarked it as answer; however, I appreciate your trying to help.   As I had said, I already had a work around.  

    What I am trying to do is open the bound datagridview in a NewMDIChild and populate it.  

    The code I am trying to use is much more complicated and the unbound columns are inserted into a bound grid.   It works with myform.show; however, if there are errors in the form that is not a child, it is harder to isolate them and step through the code and the form that is not a child also is more difficult to manage.   Is this a glitch in visual studio that they act diferently; or, is there a fix?

    I am really after a way to insert unbound columns and populate them in a child form or do something where I can step through the code in a form that is not a child.

    Thanks again...

    Monday, July 09, 2012 12:57 PM
  • Hi Jjob,

    OK, now, my suggestion is post this issue on the connect site: http://connect.microsoft.com 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 10, 2012 2:40 AM
    Moderator