Listbox only displays each character on the textbox - webforms

I am using the listbox to display them on the textbox. But I click button, it displays each character and only displays the first item. Is there any solution?
Now, I want to click items, it will display on the textbox without clicking the button. And each item is separated by a ",". So how do I do it?
Thanks so much!
protected void btnChon_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(#"Data Source=DESKTOP-R8LG380\SQLEXPRESS;Initial Catalog=PHIM;Integrated Security=True");
txtDienVien.Text = "";
foreach (var DienVienId in lbxDienVien.SelectedItem.ToString())
{
txtDienVien.Text += DienVienId + ", ";
}
}

Related

ActiveExplorer().Selection returns previously selected mail in Outlook C#

I've following code. When user clicks on Reply or Reply button, it will pass the original email which will be process on SendAndComplete button.
public partial class ThisAddIn
{
public object selectedObject = null;
Outlook.MailItem mailItem = null;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.Application application = this.Application;
Outlook.Explorer currentExplorer = application.ActiveExplorer();
//Get this event fire when selection changes
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
}
public void CurrentExplorer_Event()
{
if (this.Application.ActiveExplorer().Selection.Count == 1
&& this.Application.ActiveExplorer().Selection[1] is Outlook.MailItem)
{
selectedObject = this.Application.ActiveExplorer().Selection[1];
mailItem = selectedObject as Outlook.MailItem;
((Outlook.ItemEvents_10_Event)mailItem).Reply += new Outlook.ItemEvents_10_ReplyEventHandler(MailItem_Reply);
((Outlook.ItemEvents_10_Event)mailItem).ReplyAll += new Outlook.ItemEvents_10_ReplyAllEventHandler(MailItem_ReplyAll);
}
}
void MailItem_Reply(object response, ref bool cancel)
{
//No code here
}
void MailItem_ReplyAll(object response, ref bool cancel)
{
//No code here
}
}
Now the selectedObject will be used on Ribbon.cs on button click.
public void SendnCompleteButton_Click(Office.IRibbonControl control)
{
Outlook.Application application = new Outlook.Application();
var addIn = Globals.ThisAddIn;
Outlook.MailItem mailItem = addIn.selectedObject as Outlook.MailItem;
MessageBox.Show(mailItem.Subject + " " + mailItem.ReceivedTime + " " + mailItem.Sender.Name)
}
Message box is showing previously selected email, how do I release the previously selected object?
Thank you.
First of all, there is no need to create a new Outlook Application instance in the ribbon button's event handler:
Outlook.Application application = new Outlook.Application();
Instead, you need to use the Globals.ThisAddIn.Application property or just the add-in class which provides the Application property out of the box.
Second, you must declare the event source object at the global scope, for example:
Outlook.Explorer currentExplorer;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
currentExplorer = Application.ActiveExplorer();
//Get this event fire when selection changes
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
}
Third, checking whether a single item is selected in Outlook UI is not correct. Instead, you should check whether any item is selected:
if (this.Application.ActiveExplorer().Selection.Count > 0)

How to get list item index when user clicks on the button which is in list item in windows phone 8

I've list box in my application.
Below is the screen shot.
When user clicks on the list item, then i'm displaying detailed page.
It is handling in below selection changed listener.
private void companiesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//get the selected item from list
Company selectedItem = (Company)e.AddedItems[0];
Uri uri = new Uri("/CompanyDetailsPage.xaml", UriKind.Relative);
//navigate to target page
this.NavigationService.Navigate(uri);
FrameworkElement root = Application.Current.RootVisual as FrameworkElement;
root.DataContext = selectedItem;
}
}
Upto this it is fine.
Now when the user clicks on the Delete button which is on the item,
then i've to delete that item from the list.
private void Del_Btn_clicked(object sender, RoutedEventArgs e)
{
//get the Corresponding item from list i.e. On which delete button is placed.
//Delete saved company from the database
}
I'm unable to get that particular list item index on which the delete button is placed.
Ho could I get.
Thanks.
You can retrieve the button by casting the sender parameter. From there, you can retrieve the company by casting the DataContext property:
private void Del_Btn_clicked(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
var company = (Company)button.DataContext;
// ...
}
do get the index of the listbox you can direct set the property
SelectedIndex = {Binding asd,Mode=TwoWay}
then in viewmodel
make a property
private int _asd;
public int asd
{
get
{
return _asd;
}
set
{
_asd= value;
}
}
by this you will get the index of selected item ...
hopes it might help ..

How to delete the listbox item in wp7?

Listbox having 2 buttons.When click on button need to delete the item from that listbox.
please tell me how to acheive that?
List<SampleCheckedData> interestrates = new List<SampleCheckedData>();
interestrates = (from rts in xmlDocu.Descendants("Friend")
select new SampleCheckedData
{
Id = (string)rts.Element("userid"),
Name = (string)rts.Element("name"),
Icon = (string)rts.Element("imageurl"),
VisibleStatus = (string)rts.Element("visiblestatus"),
AppStatus = (string)rts.Element("loginstatus"),
imgBubble =bitmapRed,
}).ToList<SampleCheckedData>();
this.lstImages.ItemsSource = interestrates;
private void btnAccept_MouseEnter(object sender, MouseEventArgs e)
{
int _id = int.Parse(((System.Windows.FrameworkElement)(e.OriginalSource)).Tag.ToString());
lstFriendRequuest.Items.RemoveAt(lstFriendRequuest.SelectedIndex);
}
To delete the selected item,
listbox.Items.RemoveAt(listbox.SelectedIndex);
Make your collection available globally on this page, and now you can manipulate on it easily from btnAccept_MouseEnter event:
public interestrates;
...
{
interestrates = ...
this.lstImages.ItemsSource = interestrates;
}
private void btnAccept_MouseEnter(object sender, MouseEventArgs e)
{
interestrates.RemoveAt(lstFriendRequuest.SelectedIndex);
}
Also, make sure that a click on a ListBox item changes SelectedIndex accordingly

How to set the Title of a Panorama control from value in a query string?

When I navigate to a view with a Panorama control I would like to set the Title of the Panorama control, the Title value is coming in with a query string from the previous view. How do I do that?
if you are navigating from other page:
page.xaml,cs:
private void Navigate()
{
string name = "Test";
// Navigate to Panorama page
NavigationService.Navigate(new Uri("/Pages/PanoramaPage.xaml?name=" + name, UriKind.Relative));
}
PanoramaPage.xaml.cs:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string name = "";
if (NavigationContext.QueryString.TryGetValue("name", out name))
{
PageTitle.Text = name;
}
}

Unable to show the selected item in the Wp7 Listpicker control

Basically i am trying to pull the contacts from the phone and showing them in the Listpicker control for a feature in my app. I have two Listpickers, one for name of contacts list and the other showing the list of phonenumbers for the chosen contact.
Here is my code:
//Declarations
ContactsSearchEventArgs e1;
String SelectedName;
String SelectedNumber;
List<string> contacts = new List<string>();
List<string> phnum = new List<string>();
public AddressBook() // Constructor
{
InitializeComponent();
Contacts contacts = new Contacts();
contacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contacts_SearchCompleted);
contacts.SearchAsync(string.Empty,FilterKind.None,null);
}
void contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
e1 = e;
foreach (var result in e.Results)
{
if (result.PhoneNumbers.Count() != 0)
{
contacts.Add(result.DisplayName.ToString());
}
}
Namelist.ItemsSource = contacts;
}
private void Namelist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedName = (sender as ListPicker).SelectedItem.ToString();
phnum.Clear();
foreach (var result in e1.Results)
{
if (SelectedName == result.DisplayName)
{
phnum.Add(result.PhoneNumbers.FirstOrDefault().ToString());
}
}
Numbers.ItemsSource = phnum;
}
private void Numbers_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedNumber = (sender as ListPicker).SelectedItem.ToString();
}
Am able to populate the Numberlist with phonenumbers for the chosen name at the Listpicker background, but the number is not showing up in the front. I think Numbers_SelectionChanged() event is called only one time when the page loads and am not seeing it triggerd when i change the contact list. Anyone has an idea of where am going wrong ?
If you change
List<string>
To
ObservableCollection<string>
this should work.
Also then you only need to set the ItemSource once, in Xaml or you constructor.
But you may run into another issue with the November 2011 Toolkit and ListPicker.
See more in thread.
private void Namelist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedName = (sender as ListPicker).SelectedItem.ToString();
phnum = new List<string>(); // Changed instead of phnum.Clear()
foreach (var result in e1.Results)
{
if (SelectedName == result.DisplayName)
{
phnum.Add(result.PhoneNumbers.FirstOrDefault().ToString());
}
}
Numbers.ItemsSource = phnum;
}
This works !!. While debugging i found its phnum.Clear() giving a problem. So i thought to create a new instance of phnum list for selected contact.

Resources