Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
SuggestionRe: How to Login to my Database from C#? Pin
Richard Deeming2-Dec-16 2:09
mveRichard Deeming2-Dec-16 2:09 
AnswerRe: How to Login to my Database from C#? Pin
Gerry Schmitz2-Dec-16 8:00
mveGerry Schmitz2-Dec-16 8:00 
Questionc#webservice insert into Unity3d Pin
Member 128822191-Dec-16 19:26
Member 128822191-Dec-16 19:26 
AnswerRe: c#webservice insert into Unity3d Pin
Richard MacCutchan1-Dec-16 21:40
mveRichard MacCutchan1-Dec-16 21:40 
QuestionWPF Importing Raw Data From Excel And Want to Retain The Exact Date Format Pin
Mark McArdle1-Dec-16 4:54
Mark McArdle1-Dec-16 4:54 
AnswerRe: WPF Importing Raw Data From Excel And Want to Retain The Exact Date Format Pin
Richard Deeming1-Dec-16 5:33
mveRichard Deeming1-Dec-16 5:33 
GeneralRe: WPF Importing Raw Data From Excel And Want to Retain The Exact Date Format Pin
Mark McArdle1-Dec-16 5:38
Mark McArdle1-Dec-16 5:38 
Questionc# WPF Binding a listbox to another listbox's selected item Pin
Member 1288059530-Nov-16 22:11
Member 1288059530-Nov-16 22:11 
Hello!
I am trying to make a Contact Book, where i can have my contacts and conversations(+other activities related to them) in C# WPF.I am also trying to learn MVVM withg this.

I have 2 listboxes each bound to an observable collection populated from a database using LinqToSQL.
Listbox 1(ContactsLstBx) is displaying a list of contact names, and in Listbox 2(ConversationLstBx), i want to display the conversations i had with the selected contact in Listbox 1.

The problem is that i dont know how to get the Listbox 1 selectedItem.Id(the contact's id) so that i can use it in a query to select the conversations i had with the selected contact.

Also, any advice regarding what i am doing is highly appreciated.



C#:
C#
public class ContactViewModel : ViewModelBase
    {
        public ObservableCollection<Contact> ContactList;

        public ContactViewModel()
        {
            ContactList = new ObservableCollection<Contact>(cbdc.Contacts);
        }

public class ConversationViewModel : ViewModelBase
    {
        public ObservableCollection<Conversation> ConversationList;

        public ConversationViewModel()
        {
            ConversationList = new ObservableCollection<Conversation>(cbdc.Conversations);
        }

    }

public class ViewModelBase: INotifyPropertyChanged
    {
        public ContactLinqToSQLClassesDataContext cbdc = new ContactLinqToSQLClassesDataContext();


        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;
        internal void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion


XAML:
XML
<ListBox x:Name="ContactsLstBx" HorizontalAlignment="Left" Height="289" Margin="10,50,0,0" VerticalAlignment="Top" Width="115" ItemsSource="{Binding ContactList}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=Name}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <ListBox x:Name="ConversationLstBx" HorizontalAlignment="Left" Height="134" Margin="333,50,0,0" VerticalAlignment="Top" Width="115" ItemsSource="{Binding ConversationList}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=Title}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>



Thank You!
AnswerRe: c# WPF Binding a listbox to another listbox's selected item Pin
Pete O'Hanlon30-Nov-16 23:23
mvePete O'Hanlon30-Nov-16 23:23 
GeneralRe: c# WPF Binding a listbox to another listbox's selected item Pin
Member 128805951-Dec-16 1:46
Member 128805951-Dec-16 1:46 
Questionauto delete file Pin
Member 1287946030-Nov-16 18:41
Member 1287946030-Nov-16 18:41 
AnswerRe: auto delete file Pin
OriginalGriff30-Nov-16 20:10
mveOriginalGriff30-Nov-16 20:10 
AnswerRe: auto delete file Pin
Afzaal Ahmad Zeeshan1-Dec-16 7:20
professionalAfzaal Ahmad Zeeshan1-Dec-16 7:20 
GeneralRe: auto delete file Pin
Eddy Vluggen1-Dec-16 8:27
professionalEddy Vluggen1-Dec-16 8:27 
AnswerRe: auto delete file Pin
Gerry Schmitz1-Dec-16 9:09
mveGerry Schmitz1-Dec-16 9:09 
QuestionCan change Excel file to Object in C# window application Pin
Rosy mm30-Nov-16 15:33
Rosy mm30-Nov-16 15:33 
AnswerRe: Can change Excel file to Object in C# window application Pin
OriginalGriff30-Nov-16 20:13
mveOriginalGriff30-Nov-16 20:13 
GeneralMessage Closed Pin
30-Nov-16 22:12
Rosy mm30-Nov-16 22:12 
GeneralRe: Can change Excel file to Object in C# window application Pin
OriginalGriff30-Nov-16 22:57
mveOriginalGriff30-Nov-16 22:57 
GeneralRe: Can change Excel file to Object in C# window application Pin
Rosy mm1-Dec-16 19:01
Rosy mm1-Dec-16 19:01 
GeneralRe: Can change Excel file to Object in C# window application Pin
Richard Deeming1-Dec-16 2:07
mveRichard Deeming1-Dec-16 2:07 
AnswerRe: Can change Excel file to Object in C# window application Pin
Gerry Schmitz1-Dec-16 9:20
mveGerry Schmitz1-Dec-16 9:20 
Questionrdl report Pin
Member 1048416229-Nov-16 17:07
Member 1048416229-Nov-16 17:07 
AnswerRe: rdl report Pin
Richard Deeming30-Nov-16 2:19
mveRichard Deeming30-Nov-16 2:19 
Questionhow to get modified record from database to c# application Pin
Member 308047028-Nov-16 20:06
Member 308047028-Nov-16 20:06 

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.