Read + Write + Report
Home | Start a blog | About Orble | FAQ | Sites | Writers | Advertise | My Orble | Login

ComboBox2ListBox

May 27th 2008 04:04
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
{
/// <summary>
/// Interaction logic for combo2List.xaml

/// </summary>
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>
20
Vote


   
Subscribe to this blog 


Just this blog This blog and DailyOrble (recommended)

   

   


Add A Comment

To create a fully formatted comment please click here.


CLICK HERE TO LOGIN | CLICK HERE TO REGISTER

Name or Orble Tag
Home Page (optional)
Comments
Bold Italic Underline Strikethrough Separator Left Center Right Separator Quote Insert Link Insert Email
Notify me of replies
Notify extra people about this comment
Is this a private comment?
List the Email Addresses or Orble Tags of the people you would like to be notified about this comment


One per line max of 30

List the Email Addresses or Orble Tags of the people you would like to be notified about this private comment thread. Only the people in this list will be able to see or reply to your comment.


One per line max of 30

Your Name
(for the email going out to the above list, it can be different to your Orble Tag)
Your Email Address
(optional)
(required for reply notification)
Submit
More Posts
3 Posts
2 Posts
5 Posts dating from May 2008
Email Subscription
Receive e-mail notifications of new posts on this blog:
0

Siddharth sood's Blogs

35 Vote(s)
0 Comment(s)
1 Post(s)
76 Vote(s)
0 Comment(s)
2 Post(s)
36 Vote(s)
0 Comment(s)
1 Post(s)
48 Vote(s)
0 Comment(s)
1 Post(s)
28 Vote(s)
0 Comment(s)
1 Post(s)
69 Vote(s)
0 Comment(s)
2 Post(s)
155 Vote(s)
0 Comment(s)
4 Post(s)
4145 Vote(s)
14 Comment(s)
77 Post(s)
24 Vote(s)
0 Comment(s)
1 Post(s)
23 Vote(s)
0 Comment(s)
1 Post(s)
Moderated by Siddharth sood
Copyright © 2006 2007 2008 On Topic Media PTY LTD. All Rights Reserved. Design by Vimu.com.
On Topic Media ZPages: Sydney |  Melbourne |  Brisbane |  London |  Birmingham |  Leeds     [ Advertise ] [ Contact Us ] [ Privacy Policy ]