C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Adding a Combobox to ListBox in XAML


Posted Date: 09 Jul 2008    Resource Type: Code Snippets    Category: Visual Studio
Author: siddharthMember Level: Bronze    
Rating: Points: 7



This sample code is another example on Memeber Binding, where one contol is bound to another. This example contains a C# code and XAML code.

C# code for selecting ComboBox item into ListBox:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;

namespace WpfApplication1_grid
{
///
/// Interaction logic for combo2List.xaml
///

public partial class combo2List : System.Windows.Window
{
public combo2List()
{
InitializeComponent();
comboBox1.SelectionChanged = new SelectionChangedEventHandler( comboBox1_SelectionChanged);
}

void comboBox1_SelectionChanged(ob ject sender, SelectionChangedEventArgs e)
{
//throw new NotImplementedException();
string strItem = "";
System.Data.DataRowView dr = (System.Data.DataRowView)comb oBox1.SelectedItem;
strItem = dr.Row["firstname"].ToString();
listBox1.Items.Add(strItem);

}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ListCat();
}

private void ListCat()
{
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection("Data source=cp960sw;initial catalog=VH-ENH-POC;uid=sa;pas sword=rmsindia;");
SqlDataAdapter da = new SqlDataAdapter("Select * from student", con);
da.Fill(ds);
comboBox1.DataContext = ds.Tables[0].DefaultView;
comboBox1.DisplayMemberPath = ds.Tables[0].Columns[1].ToString();
comboBox1.SelectedValuePath = ds.Tables[0].Columns[0].ToString();
}
}
}



XAML code for selecting ComboBox item into Listbox:


<Window x:Class="WpfApplication1_grid .combo2List"
Really Long Link
Really Long Link
Title="combo2List" Height="300" Width="300" Loaded="Window_Loaded">
<Grid>
<ComboBox Height="23" Margin="104,43,54,0" ItemsSource="{Binding}" Name="comboBox1" VerticalAlignment="Top" IsSynchronizedWithCurrentItem ="False"></ComboBox>
<ListBox Margin="102,121,56,41" Name="listBox1" IsSynchronizedWithCurrentItem ="False" />
</Grid>
</Window>







Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Using DisplayMemberBinding property  .  Member Binding in WPF  .  Combobox  .  Add Combobox to ListView in WPF  .  Add Combobox to ListView  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Autogeneration numbers...
Previous Resource: Create PDF document using C#
Return to Discussion Resource Index
Post New Resource
Category: Visual Studio


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use