Make Datagridview Part of UI and use the input values with class object

Hobbyist_programmer 621 Reputation points
2021-02-05T20:16:24.01+00:00

Hallo,

I am trying figure out for more than a month but with my current knowledge it seems impossible. Currently i have a datagridview as shown in screenshot. it is a kind of template with predefined objects bound to datagridview and it is part of the UI it is always there and i have a class called Work and it is instances are bound to another datagridview where i can add more instances or remove them. Every work instance can have different set of man hour values , if user enters the new value, cost will be calculated with user value. here i want to save only the inputs from the datagrid view with my object instances. How can i do that? Any help will be much appreciated.

Public Class Form1  
  
    Public TemplateList As New List(Of Template)  
    Public BS_TemplateList As New BindingSource  
    Public WorkList As New List(Of Work)  
    Public BS_WorkList As New BindingSource  
  
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
  
        TemplateList.Add(New Template With {.ID = 1, .Description = "Discription 1", .HourDefault = 1, .UnitPrice = 5})  
        TemplateList.Add(New Template With {.ID = 2, .Description = "Discription 2", .HourDefault = 1, .UnitPrice = 10})  
        TemplateList.Add(New Template With {.ID = 3, .Description = "Discription 3", .HourDefault = 1, .UnitPrice = 15})  
        TemplateList.Add(New Template With {.ID = 4, .Description = "Discription 4", .HourDefault = 1, .UnitPrice = 20})  
  
        BS_TemplateList.DataSource = TemplateList  
        DataGridView1.DataSource = BS_TemplateList  
  
        BS_WorkList.DataSource = WorkList  
        DataGridView2.DataSource = BS_TemplateList  
  
    End Sub  
  
  
  
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click  
        BS_WorkList.Add(New Work With {.WorkID = 1, .Item = "Work1"})  
    End Sub  
  
End class  
  
Public Class Template  
    Public Property ID As Integer  
    Public Property Description As String  
    Public Property Hour As Integer?  
    Public Property HourDefault As Integer  
    Public Property UnitPrice As Integer  
    Public ReadOnly Property Cost As Integer  
        Get  
            If Hour > 0 Then  
                Return Hour * UnitPrice  
            Else  
                Return HourDefault * UnitPrice  
            End If  
        End Get  
    End Property  
    Public Property Remarks As String  
  
End Class  
  
Public Class Work  
    Public Property WorkID As Integer  
    Public Property Item As String  
    Public Property TemplateID As Integer  
    Public Property Hour As Integer  
    Public Property Remarks As String  
End Class  

64735-2021-02-05-11-56-16.jpg

Thanks

Developer technologies | VB
{count} votes

6 answers

Sort by: Most helpful
  1. Hobbyist_programmer 621 Reputation points
    2021-02-08T20:04:36.973+00:00

    Hallo Peter Thanks it works almost as expected but one problem , if i go to previous bidder and change the value , new value is not being updated or saved. how can i make it save or update as i type?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.