Results 1 to 2 of 2

Thread: WPF: databinding to an array example in vb.net

  1. #1

    Thread Starter
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    WPF: databinding to an array example in vb.net

    Hi all,

    Well as many users here will no doubt have discovered, getting a tutorial in vb.net explaining how to bind an array to say a datagrid is nigh on impossible, many examples abound that explain the process in c# but on translation all kinds of issues arise and the end is result is a page full of errors and no working code. So I am building a testbed example to come to terms with this process and hopefully get advice from vb members with wpf experiance.

    For my Example i have decided to go for an app that constructs an array of cards and binds the card values and colours to a datagrid. This i will break down into 4 classes:-
    1/ A Card object consisting of 3 properties:- CardName, Colour and a bool IsDealt which is false unless the card has been dealt (which will show on the final datagrid greyed out if it is true)
    2/ A Deck array which contains the 52 cards that make up a deck.
    3/ A convertor which will take a card object and create a Text field in the correct colour (grey if selected already
    4/ a view which will contain a datagrid which is to be dynamically populated via the array contents for Deck

    step 1 is easy and i have chosen to do this in a structure
    vb.net Code:
    1. Public Structure Card
    2. Public CardName as String ' example 4S is four of spades, TH is ten of hearts
    3. Public Colour As Color ' Red or Black for now
    4. Public IsDealt as Boolean
    5. End Structure

    Step 2 is easy enough i wont include all the routine for simplicity but this class would look like this.
    vb.net Code:
    1. Public Class Cards
    2. Public Deck(12,3) as Card ' our array of cards
    3. Sub New()
    4. InitializeComponent
    5. FillDeck()
    6. End Sub
    7.  
    8. Private Sub FillDeck()
    9. ' Nested loop to populate the deck with 52 card objects
    10. End Sub
    11. End Class
    So far so good, the Deck array is filled with the correct Data

    From this point on the info for vb.net is as rare as Rocking Horse Doodah
    Choices abound as to what to do, should i create an observableView bound to the Deck and bind the array to this or is there a way i can simply bind direct to the array? Example threads i have read suggest implementing Window, trying this creates an error that window is not implementable. Perhaps using a Data Template is better than a grid but again examples are rare if at all.

    Say we forget about the colour and IsSelected Fields in the structure and just display the text from the array on the datagrid, how would this be done in VB.Net? what if i want all features? will it be best to use a convertor as initialy invisaged?

    This whole wpf binding examples examples in C# looks increasiingly like an effort to sideline the abilities of vb.net. I am presuming that the data binding functionality of vb.net is identical to C# but it may be syntatically different...

    Maybe someone here knows of a good tutorial that explains databinding to an array of objects using VB.Net?

    P.S. if there is one could it be placed on a sticky for future wpf vb.net developers who use our site.
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

  2. #2

    Thread Starter
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: WPF: databinding to an array example in vb.net

    http://support.microsoft.com/kb/315784 looks promising...

    ah ok thats windows forms...
    Last edited by Megalith; Mar 8th, 2011 at 11:27 AM.
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

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