Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to capture value of listbox item
    primarykey
    data
    text
    <p>I am trying to capture the value of the selected item in a list box, and store that value into my database. My goal is when I choose "Male" (or "Female") the "Male" (or "Female") will be added to the Gender [column] in the database but I don't know how to do it.</p> <p>MyDatabase:</p> <pre><code>[Table] public class Member : INotifyPropertyChanged, INotifyPropertyChanging { // Define ID: private field, public property, and database column. private int _ID; [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)] public int ID { get { return _ID; } set { if (_ID != value) { NotifyPropertyChanging("ID"); _ID = value; NotifyPropertyChanged("ID"); } } } private string _FullName; [Column] public string FullName { get { return _FullName; } set { if (_FullName != value) { NotifyPropertyChanging("FullName"); _FullName = value; NotifyPropertyChanged("FullName"); } } } private string _Address; [Column] public string Address { get { return _Address; } set { if (_Address != value) { NotifyPropertyChanging("Address"); _Address = value; NotifyPropertyChanged("Address"); } } } private string _Gender; [Column] public string Gender { get { return _Gender; } set { if (_Gender != value) { NotifyPropertyChanging("Gender"); _FullName = value; NotifyPropertyChanged("Gender"); } } } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; // Used to notify that a property changed private void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } #endregion #region INotifyPropertyChanging Members public event PropertyChangingEventHandler PropertyChanging; // Used to notify that a property is about to change private void NotifyPropertyChanging(string propertyName) { if (PropertyChanging != null) { PropertyChanging(this, new PropertyChangingEventArgs(propertyName)); } } #endregion } public class GenderPicker { public string sex { get; set; } } </code></pre> <p>My ListPicker list:</p> <pre><code>public Add() { InitializeComponent(); this.DataContext = App.MainViewModel; List&lt;GenderPicker&gt; picker = new List&lt;GenderPicker&gt;(); picker.Add(new GenderPicker() { sex = "Male" }); picker.Add(new GenderPicker() { sex = "FeMale" }); this.ListPicker.ItemsSource = picker; } </code></pre> <p>My Add Button: I dont know what can be filled in ???????????????</p> <p>Member is the table. Column is FullName | Address | Gender</p> <pre><code>private void Add_Click(object sender, EventArgs e) { if ((addaddress.Text.Length &gt; 0) &amp;&amp; (addfullname.Text.Length &gt; 0)) { Member newInfo = new Member { FullName = addfullname.Text, Address = addaddress.Text, Gender = ???????????????? }; App.MainViewModel.Addinfo(newInfo); } } </code></pre> <p>And my selection changed in LIstpicker:</p> <pre><code> private void ListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e) { var samplesex =(GenderPicker)ListPicker.SelectedItem; var selectedsex = (samplesex.sex).ToString(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload