Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Since retiring in 1997 I have concentrated upon researching and publishing material and a website at www.bobagans.org , this I call this my vocation. My second pursuit has been in the area of general computing to eventually decide what particular segment of computing I wished to major upon, this I call my hobby.

My present website is my third one that I started on January 5, 2008 at the age of seventy-one. The software that I have used is Microsoft’s 2005, 2008, and now VS 2010 Express ASP.NET 4.
Primary books used:
1. Beginning ASP.NET 4 in C# and VB, by Imar Spaanjaars from the Netherlands, and published by Wrox publishing in 2010. I have found this book to be the one that best explained the basics of computer web design.
2. Professional ASP.NET 4 in C# and VB, by Bill Even, Scott Hansel man, and Devin Rader, also a 2010 Wrox publication. This book, also very informative is quite a bit beyond my ability and probably includes things I will never be interested in.

Concerning my computer hobby, I have narrowed my interests to Microsoft’s VS 2010 Express Visual Basic and .NET 4, which contains and embraces several other platforms. The platforms I am using and wish to learn more thoroughly are Windows Presentation Foundation (WPF), Entity Framework (EF) and Visual Basic (VB); I especially like and enjoy Extensible Application Markup Language (XAML).
Primary books used:
1. Visual Basic 2005 - Programmer’s Reference, by Rod Stephens, a 2005 Wrox publication.
2. Professional Visual Basic 2010 and .NET 4, by several authors and also a Wrox 2010 publication.
3. Pro WPF in VB 2010 in .NET 4, by Matthew MacDonald, a 2010 Apress publication.

These and other books and publications that I have read explained that WPF was a new way of doing Windows Applications, the former way was by using Windows Forms, which I had used until 2010. While WPF has a much greater potential, it is also much harder to learn. Also, because it is so new, there is a shortage of information on how to do some of what I have in the past done with Windows Forms. Over the past year I have searched the book stores and the internet without much success, because the specific information I am looking for is how to edit, save and update to the database the WPF datagrid, and then get individual cell data to use in calculations for updating other data tables. The paragraph below will give you an idea of why I am looking for these particular features. I am not a developer or skilled programmer, merely someone who enjoys working with these platforms. Can you suggest a good and simple source of Visual Basic information on the WPF datagrid to accomplish these goals?

From about 1984 until the plant closed down in Dec. of 1997 I worked in the office as Business and Engineering Administrator for ParaFab Engineering in Lockeford CA., where I developed a Dos Paradox3 business application that handled everything in the office but the making of mechanical drawings. Payroll, purchases and sales, job records and reports and two inventories were all part of this application. I retired in 1998 and soon after began updating the ParaFab business app. to Paradox5 for Windows, just for my own personal enjoyment. In 2004 I became aware of and began to use VB 2005 Express to continue my interest in updating some of this same business application’s functions; since then I have used each new Express edition, both for the web and for the business app. Now I am trying to update some of my business applications functions to WPF.

Latest update:

I think I have found the book I need to answer the questions I previously posted here: Julia Lerman’s book, Programming Entity Framework – the 2010 second edition. I have come to the conclusion that I need to learn EF more thoroughly before I can proceed with WPF datagrid.

3/19/2011
I was misinformed about Julie’s book, Programming Entity Framework; the code in it is mostly written in C# with very little in Visual Basic. But it does illustrate the complexity of Entity Framework, and leaves me with little hope that I will be able to find the information I need to edit, find and use individual cell information and then update the database using WPF datagrid in Visual Basic.

5/14/2011
I have switched from Entity Framework to LINQ to SQL to work with my WPF DataGrids and applications, as a result I have been able to go forward with the app's I am working on. Instead of trying to get individual cell contents through VB code, I'm using queries and arrays or queues to get and arrange the contents; this is working well for me, so I will probably not need the information I first requested.

Here is a typical example of the VB code behind to build a customer invoice:
VB
Private Sub btnWriteInvoice_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnWriteInvoice.Click
        'Me.spInvoice.ClearValue()  'how can I start over every time through?
        'Create TextBlocks for StackPanal spInvoice
        Dim TextBlock48 = New TextBlock()
        TextBlock48.VerticalAlignment = Windows.VerticalAlignment.Top
        TextBlock48.HorizontalAlignment = Windows.HorizontalAlignment.Center
        TextBlock48.Text = "NorthWind Food Specialists"

        Dim TextBlock49 = New TextBlock()
        TextBlock49.Margin = New Thickness(0, 0, 0, 15)
        TextBlock49.VerticalAlignment = Windows.VerticalAlignment.Top
        TextBlock49.HorizontalAlignment = Windows.HorizontalAlignment.Center
        TextBlock49.Text = Today

        'Get Purchase order number
        Dim strOID As String = ""
        strOID = TextBox1.Text
        'strOID = DataGrid2.Items.CurrentItem.ToString()    'gets the whole first row, always
        'strRow = DataGrid2.Items.GetItemAt(strOID).ToString  'gets the row of the number that I put in TextBox1
        'strRow = DataGrid2.Items.CurrentPosition.ToString()    'always gets "0"
        'strIndexNum = DataGrid2.CurrentItem.ToString() 'throws an exception

        'Entity join query to get each item in the Order_Details table
        Dim detailShow = From qi In db.Order_Details
                         Join pro In db.Products On qi.ProductID Equals pro.ProductID
                         Where qi.OrderID = strOID
                         Select qi.OrderID, qi.ProductID, pro.ProductName, qi.Quantity, qi.UnitPrice

        Me.DataGrid1.ItemsSource = detailShow

        Dim quan = From q In detailShow
                   Select q.Quantity

        ' Creates and initializes a new Queue to store in an array or Queue the Quan.
        Dim lops As Integer = 0
        Dim lop2 As Integer = 1
        Dim myQ As New Queue()
        For Each q In quan
            myQ.Enqueue(q)    'Adds each item quanity to an array or Queue
            lops = lops + 1
        Next

        Dim name = From n In detailShow
                   Select n.ProductName

        ' Creates and initializes a new Queue to store in an array or Queue the Name of the Product.
        lops = 0
        lop2 = 1
        Dim myQ2 As New Queue()
        For Each n In name
            myQ2.Enqueue(n)    'Adds each item name to an array or Queue
            lops = lops + 1
        Next

        Dim cost = From c In detailShow
                   Select c.UnitPrice

        ' Creates and initializes a new Queue to store in an array or Queue the Cost of the Product.
        lops = 0
        lop2 = 1
        Dim myQ3 As New Queue()
        For Each c In cost
            myQ3.Enqueue(c)    'Adds each item cost to an array or Queue
            lops = lops + 1
        Next

        'Stores the array elements into variables
        Dim strNam As String = "Hello"
        Dim intQuan As Integer = 1
        Dim sngCost As Single = 1.1
        Dim TotalCost As Single = 1.1
        Dim TotalCost2 As Single = 0
        Dim txtBlock As String = "Put together"

        Dim TextBox11 = New TextBox()
        TextBox11.Width = 0
        TextBox11.Height = 0

        Dim cusName As String = TextBox2.Text
        Dim TextBox10 = New TextBox()
        TextBox10.Width = 0
        TextBox10.Height = 0

        Dim TextBlock50 = New TextBlock()
        TextBlock50.Margin = New Thickness(0, 0, 40, 0)
        TextBlock50.VerticalAlignment = Windows.VerticalAlignment.Top
        TextBlock50.HorizontalAlignment = Windows.HorizontalAlignment.Right

        Dim TextBlock51 = New TextBlock()
        TextBlock51.Margin = New Thickness(0, 0, 40, 0)
        TextBlock51.HorizontalAlignment = Windows.HorizontalAlignment.Right

        Dim TextBlock52 = New TextBlock()
        TextBlock52.Margin = New Thickness(0, 0, 40, 0)
        TextBlock52.HorizontalAlignment = Windows.HorizontalAlignment.Right

        Dim TextBlock53 = New TextBlock()
        TextBlock53.Margin = New Thickness(0, 0, 40, 0)
        TextBlock53.HorizontalAlignment = Windows.HorizontalAlignment.Right

        Dim TextBlock54 = New TextBlock()
        TextBlock54.Margin = New Thickness(0, 0, 40, 0)
        TextBlock54.HorizontalAlignment = Windows.HorizontalAlignment.Right

        Dim TextBlock55 = New TextBlock()
        TextBlock55.Margin = New Thickness(0, 0, 40, 0)
        TextBlock55.HorizontalAlignment = Windows.HorizontalAlignment.Right

        Dim TextBlock56 = New TextBlock()
        TextBlock56.Margin = New Thickness(0, 0, 40, 0)
        TextBlock56.HorizontalAlignment = Windows.HorizontalAlignment.Right

        Dim TextBlock57 = New TextBlock()
        TextBlock57.Margin = New Thickness(0, 0, 40, 0)
        TextBlock57.HorizontalAlignment = Windows.HorizontalAlignment.Right

        'Unites the variables into a textblock
        For i = 1 To lops
            intQuan = myQ.Dequeue
            strNam = myQ2.Dequeue
            sngCost = myQ3.Dequeue
            TotalCost = intQuan * sngCost
            TextBox11.Text = TotalCost
            TextBox11.Text = Format(TotalCost, "$###0.00")
            TotalCost2 += TotalCost
            txtBlock = strNam & "  <>  " & intQuan & "  ea @  " & sngCost & "=  " & TextBox11.Text

            Select Case i
                Case 1
                    TextBlock50.Text = txtBlock
                Case 2
                    TextBlock51.Text = txtBlock
                Case 3
                    TextBlock52.Text = txtBlock
                Case 4
                    TextBlock53.Text = txtBlock
                Case 5
                    TextBlock54.Text = txtBlock
                Case 6
                    TextBlock55.Text = txtBlock
                Case 7
                    TextBlock56.Text = txtBlock
            End Select
        Next

        TextBox10.Text = Format(TotalCost2, "$###0.00")
        txtBlock50 = "Total cost of all items for our customer, " & cusName & "=  " & TextBox10.Text

        If lops = 1 Then
            TextBlock51.Text = txtBlock50
        End If

        If lops = 2 Then
            TextBlock52.Text = txtBlock50
        End If

        If lops = 3 Then
            TextBlock53.Text = txtBlock50
        End If

        If lops = 4 Then
            TextBlock54.Text = txtBlock50
        End If

        If lops = 5 Then
            TextBlock55.Text = txtBlock50
        End If

        If lops = 6 Then
            TextBlock56.Text = txtBlock50
        End If

        If lops > 7 Then
            TextBlock57.Text = txtBlock50
        End If

        'Place the TextBlocks in spInvoice
        Dim container As IAddChild = spInvoice
        container.AddChild(TextBlock48)
        container.AddChild(TextBlock49)
        container.AddChild(TextBlock50)
        container.AddChild(TextBlock51)
        container.AddChild(TextBlock52)
        container.AddChild(TextBlock53)
        container.AddChild(TextBlock54)
        container.AddChild(TextBlock55)
        container.AddChild(TextBlock56)
        container.AddChild(TextBlock57)
    End Sub

Bob
Posted
Updated 14-May-11 16:10pm
v11
Comments
Venkatesh Mookkan 9-Mar-11 21:50pm    
Too big story to read my friend.

Ask your question simple and straight.

I bet nobody here has time to ready your story.

Have you seen this walkthrough on MSDN[^]?

It covers the basics of CRUD.
 
Share this answer
 
Comments
Member 7733425 20-Mar-11 0:21am    
Hi Henry Minute,
I want to thank you taking the time to direct me to this walkthrough, I had seen it before but had not taken the time to examine it. It is an interesting project showing the use of more than one page, and it does use WPF and the datagrid, but only in a basic way. What it doesn’t show is how to use it in conjunction with Entity Framework to edit and manipulate the WPF datagrid, and then update it to the database. But I do appreciate your response!
Bob
Henry Minute 20-Mar-11 10:33am    
For something on WPF and EF take a look at http://msdn.microsoft.com/en-us/data/gg610409 which contains a download in VB.Net. I haven't read all of it myself yet but it doesn't seem to use the DataGrid, useful stuff all the same. For more on the DataGrid I like the http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx#xx3520739xx article here on Code Project. The code-behind is C#, unfortunately, but as it is mostly about the xaml you may be able to get enough from it to be useful.

Good luck!
Member 7733425 20-Mar-11 20:56pm    
Hello again Henry Minute,

My friend, this link to msdn. . . . . . /gg610409 is just the information I have been looking for, I can’t thank you enough. There is a Visual Basic download available at the top of the article that I downloaded and successfully run. The only thing I cannot get it to do is to save the changes or editing of the datagrid back to the database. I have asked Julie if she could tell me why, but I haven't heard from her yet. I will also look at the other links you so graciously provided to see if they can be of further help.


I was also surprised and pleased that this article was written by Julie Lerman whose book I already have. I have read through Julie’s book, and it touches on many of the subjects and objects I’m interested in, but it never goes into specific detail on how to use WPF datagrid and Entity Framework to edit and update the database. The article does, and step by step explains why and how; it’s the best and clearest information I have ever read, and I have you to thank for it.

Bob
Henry Minute 20-Mar-11 21:08pm    
Pleased to help.

Good Luck! :)
Henry Minute 20-Mar-11 18:19pm    
In case you haven't seen it, I have just stumbled upon "VB EntityFramework Samples Now Available" -->http://dotnetslackers.com/Data/re-214992_VB_Entity_Framework_Samples_Now_Available_Lisa_Feigenbaum.aspx
Watch the first video how to creat a database from here. http://msdn.microsoft.com/en-us/vbasic/ff718212[^]

Then the rest videos how to connect the database to wpf
http://msdn.microsoft.com/en-us/vbasic/ff718210[^]

Hope this helps
 
Share this answer
 
v2
Comments
Member 7733425 24-Mar-11 17:09pm    
Hi Stanz,

I Thank you for your information, but the first link only uses Windows forms and list views, and the second only uses WPF and list views that contain a datagrid – not the new Datagrid that is used by itself. What I am interested in doing is building projects using the new way of doing Windows, by combining the two separate platforms of WPF with the new WPF Datagrid, and Entity Framework (especially the LINK to Entities method) all using the VB language.

Bob

P.S.
I have made some changes to my first reply to you, and don't be sorry because I couldn't use the links you mentioned because I really appreciate your help! I'm especially going to look at the site you mentioned below about converting C# into VB, thanks again,
Bob
Stanz 24-Mar-11 19:11pm    
Sory it is hard to find stuff for vb. I usually look for any code and if it is in c# than I convert it to vb using this site http://converter.telerik.com/
I am also looking for similar stuff. This is probably not what you are looking for but might help

http://community.visual-basic.it/alessandroenglish/archive/2009/06/15/25689.aspx
http://community.visual-basic.it/alessandroenglish/archive/2009/06/18/25703.aspx
http://community.visual-basic.it/alessandroenglish/archive/2010/08/13/31861.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900