Results 1 to 18 of 18

Thread: Sorting data in a combobox using the underlying data model

Threaded View

  1. #17
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Sorting data in a combobox using the underlying data model

    Quote Originally Posted by larrycav View Post
    People come here because the don't know it all. That MS article you pointed me to was of very little help to me. You read it and it all makes perfect sense. When you're a beginning programmer it often doesn't. Time and again I've see you unleash your temper on newbies.
    Correct, none of us know it all. The MSDN documentation is an acquired taste, one you should develop. If it doesn't make sense the first time read it until it does, or read some other articles. You might be surprised at JMC's response if you had said, "I read the article and didn't understand ______________." The ______________ is important, without it you get some more JMC charm

    We have all been there, the terminology is daunting, but JMC and MSDN use it correctly more often than not. It is a foreign language that must be learned. The JMC whip has seen my back a few times, but instead of being continually offended I became a voyeur, reading posts by JMC just to see who he was lashing. A funny thing happened; I noticed that he REALLY helped those that try to help themselves. JMC says his patience is depleted, but he takes the time to write what I summarize with an acronym, RTFM.

    Up to this time my knowledge of the tools that can be used to manipulate data and forms is primitive at best. Binding what, data what, etc. In my job I have to get better at this, so I read posts about data. You may not have followed JMC's advice but I did and there on the very page was an example. Here is my first attempt, using the example, at trying to see how it all fits together:
    Code:
    Public Class Form1
    
        Private Sub Buttons_Click(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click
            If myBS.Position = myBS.List.Count - 1 Then
                myBS.MoveFirst()
            Else
                myBS.MoveNext()
            End If
        End Sub
    
        Dim myDS As New DataSet()
        Dim myBS As New BindingSource()
    
        Private Sub PopulateData()
    
            ' Some xml data to populate the DataSet with. 
            Dim musicXml As XElement = <music>
                                           <recording><artist>Coldplay</artist><cd>X&amp;Y</cd></recording>
                                           <recording><artist>Dave Matthews</artist><cd>Under the Table and Dreaming</cd></recording>
                                           <recording><artist>Natalie Merchant</artist><cd>Tigerlily</cd></recording>
                                           <recording><artist>U2</artist><cd>How to Dismantle an Atomic Bomb</cd></recording>
                                           <recording><artist>Dave Matthews</artist><cd>Live at Red Rocks</cd></recording>
                                       </music>
    
            ' Read the xml. 
            Dim ms As New IO.MemoryStream
            musicXml.Save(ms)
            ms.Seek(0L, IO.SeekOrigin.Begin)
            myDS.ReadXml(ms)
    
            ' Get a DataView of the table contained in the dataset. 
            Dim tables As DataTableCollection = myDS.Tables
            Dim view1 As New DataView(tables(0))
    
            ' Create a DataGridView control and add it to the form. 
    
            ' Create a BindingSource and set its DataSource property to 
            ' the DataView. 
            myBS.DataSource = view1
    
            ' Sort the data source 
    
            'myBS.Sort = "cd"
            myBS.Sort = "artist, cd DESC"
    
            TextBox1.DataBindings.Add("text", myBS, "artist")
            TextBox2.DataBindings.Add("text", myBS, "cd")
        End Sub
    
        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            PopulateData()
        End Sub
    End Class
    You didn't need to even jump into the conversation. The other guys, with personalities that aren't 80 Grit were helping me just fine. Then you come along with your condescending attitude pretending to answer the question when your hidden agenda was really to attack. You're a sharp, seasoned programmer. That's painfully obvious. What you are NOT is a teacher. In future, just stay out of my conversations.
    As often is the case I am glad he did, I learned something. My experience with JMC is that there is nothing hidden, he speaks his mind. My flying instructor was from South Africa and she had one rule; when she said she "had the plane" she meant it. On one early lesson, low and slow on short final, she uttered those words and my hands and feet did not move quickly away from the controls, she cracked me with a flight computer. It never happened again.

    IMHO JMC is a great teacher so long as the student tries to help themselves. If you read all of his posts you will see that the "attack" on you was not personal, he advises all the same. You will also see some of the most well written, informative answers here. Read them at least twice.

    Read his posts in this thread again. He never said anything critical of you personally, though you might have reasoned that you were the one that was lazy. It didn't stop you from saying, "What you are NOT is a teacher." Something about glass houses comes to mind.

    You should hope that JMC doesn't take your request to heart.

    All of us that have been here a long time like to see people try and help themselves. "Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime."
    Last edited by dbasnett; Jul 3rd, 2015 at 07:11 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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