Click here to Skip to main content
15,887,135 members
Home / Discussions / WPF
   

WPF

 
QuestionBinding in two way mode from a XML file to a combobox in usercontrol [modified] Pin
npuleio13-Aug-11 3:57
npuleio13-Aug-11 3:57 
QuestionAccessing function on Usercontrol hosted from Window in MVVM and C# Pin
Alisaunder12-Aug-11 5:55
Alisaunder12-Aug-11 5:55 
AnswerRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
SledgeHammer0112-Aug-11 6:52
SledgeHammer0112-Aug-11 6:52 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# [modified] Pin
Alisaunder12-Aug-11 7:25
Alisaunder12-Aug-11 7:25 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
SledgeHammer0112-Aug-11 7:42
SledgeHammer0112-Aug-11 7:42 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
Alisaunder12-Aug-11 8:12
Alisaunder12-Aug-11 8:12 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
SledgeHammer0112-Aug-11 8:38
SledgeHammer0112-Aug-11 8:38 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# [modified] Pin
Alisaunder12-Aug-11 10:26
Alisaunder12-Aug-11 10:26 
Kind of understand some but still confused. Below is the class I'm constructing

C#
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace Manufactured_Housing_Manager
{
     public class ContactCollection : ObservableCollection<Contact>
    {
        #region left, right, mid string functions

        public static string left(string param, int length)
        {
            //we start at 0 since we want to get the characters starting from the
            //left and with the specified length and assign it to a variable
            string result = param.Substring(0, length);
            //return the result of the operation
            return result;
        }

        public static string mid(string param, int startIndex, int length)
        {
            //start at the specified index in the string and get the number of
            //characters depending on the length and assign it to a variable
            string result = param.Substring(startIndex, length);
            //return the result of the operation
            return result;
        }

        public static string right(string param, int length)
        {
            //start at the index based on the length of the string minus
            //the specified length and assign it a variable
            string result = param.Substring(param.Length - length, length);
            //return the result of the operation
            return result;
        }

        #endregion

         public ContactCollection() : base()
         {
             Add(new Contact("Davis, Adam T.", 0));
             Add(new Contact("Zappa, Frank M.", 1));
             Add(new Contact("Henry, Victor", 2));
             Add(new Contact("Vern, Jules W.", 3));
         }

    }

     public class Contact
     {
         private string _name;
         private int _id;
         public string Name
         {
             get { return _name; }
             set { _name = value; }
         }

         public int Id
         {
             get { return _id; }
             set { _id = value; }
         }

         public Contact()
         {
         }

         public Contact(string name, int id)
         {
             _name = name;
             _id = id;
         }
     }
}


Thing is I need to open my OLEDB Database to populate my dataset then I populate ObservableCollection<contact> with the names from each Contact in my database. I used the following code in the past to populate the tree and concate the names into one name information field I used to display.

C#
//add letters sort nodes
for (int i = System.Convert.ToInt32('A'); i <= System.Convert.ToInt32('Z'); i++)
{
    MyTreeView.Items.Add(new tvIndex(Convert.ToString((char)(i)), contactdata)); //set text

    //add customers
    contactdata = new ObservableCollection<Contact>();
    string sContactsName = null;
    foreach (DataRow rowContacts in Properties.Settings.Default.DtContacts.Rows)
    {
        sContactsName = string.Concat(rowContacts["LastName"].ToString(), ", ", rowContacts["FirstName"].ToString());

        if (!(System.Convert.IsDBNull(rowContacts["MiddleInitial"].ToString())))
        {
            if (!(rowContacts["MiddleInitial"].ToString() == ""))
                sContactsName = string.Concat(sContactsName, " ", rowContacts["MiddleInitial"].ToString(), ".");
        }

        if (left(sContactsName, 1) == Convert.ToString((char)(i + 1)))
        {
            string temp = rowContacts["ContactID"].ToString();
            contactdata.Add(new Contact(sContactsName, Convert.ToInt32(temp)));
        }
    }


In this way I simply added the base A-Z to the parent Node in the Treeview and then bound childnodes to the contactdata name and assigned the id to pull up the record.

My confusion stems from trying to implement the proper way of doing the same thing in this new public class based on ContactCollection : ObservableCollection<contact>.

As you can see I added a base which can manually add names and id's to the Collection. This gives me a certain amount of sample data to see if binding is correct. I should place my code here that imports my Dataset information, Concats the Last,First,MI into one name value and gives the id.

modified on Friday, August 12, 2011 4:35 PM

GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
SledgeHammer0112-Aug-11 11:01
SledgeHammer0112-Aug-11 11:01 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# [modified] Pin
Alisaunder12-Aug-11 13:32
Alisaunder12-Aug-11 13:32 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
Alisaunder13-Aug-11 11:25
Alisaunder13-Aug-11 11:25 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
SledgeHammer0113-Aug-11 11:49
SledgeHammer0113-Aug-11 11:49 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
Alisaunder13-Aug-11 15:09
Alisaunder13-Aug-11 15:09 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
SledgeHammer0113-Aug-11 15:35
SledgeHammer0113-Aug-11 15:35 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
Alisaunder14-Aug-11 14:36
Alisaunder14-Aug-11 14:36 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
SledgeHammer0114-Aug-11 15:04
SledgeHammer0114-Aug-11 15:04 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
Alisaunder15-Aug-11 22:01
Alisaunder15-Aug-11 22:01 
Questionsiilverlight 4 - listbox to have Tag Pin
arkiboys12-Aug-11 4:32
arkiboys12-Aug-11 4:32 
AnswerRe: siilverlight 4 - listbox to have Tag Pin
#realJSOP12-Aug-11 6:32
mve#realJSOP12-Aug-11 6:32 
Questionsilverlight listbox - fill colour Pin
arkiboys12-Aug-11 4:24
arkiboys12-Aug-11 4:24 
AnswerRe: silverlight listbox - fill colour Pin
Mycroft Holmes12-Aug-11 23:44
professionalMycroft Holmes12-Aug-11 23:44 
GeneralRe: silverlight listbox - fill colour Pin
arkiboys13-Aug-11 22:10
arkiboys13-Aug-11 22:10 
QuestionWPF Webbrowser bot releasing PDF file -- Help Needed Pin
pal2ashish12-Aug-11 0:36
pal2ashish12-Aug-11 0:36 
AnswerRe: WPF Webbrowser bot releasing PDF file -- Help Needed Pin
Alisaunder12-Aug-11 14:14
Alisaunder12-Aug-11 14:14 
GeneralRe: WPF Webbrowser bot releasing PDF file -- Help Needed Pin
pal2ashish14-Aug-11 4:19
pal2ashish14-Aug-11 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.