Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

ComboBox returns null value or diffrent value than needed, after selecting a displayed member

$
0
0
 I am trying to create a Windows Form Application where I insert values for a contract, and in this contract I need the ID of the employee that worked on it. I've added a ComboBox and added the name and surname of a selected employee to the display member and added the ID to it's value member. After I select one employee, my selection is stuck in the ComboBox until I write a number since it's either selecting a null value or a String. I've connected the database with LINQ.

This is my code for the ComboBox selection:

 private void vrabotenIDComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {

                var imeVrab = (from vrab in dc.Vrabotenis
                              orderby vrab.VrabotenID
                              select new { vrab.VrabotenID, VImeP = vrab.Ime + " " + vrab.Prezime }); //selecting employeeID(VrabotenID) and selecting employee name and surname (VimeP)
               vrabotenIDComboBox.DataSource = imeVrab.ToList();
               vrabotenIDComboBox.DisplayMember = "VImeP";
               vrabotenIDComboBox.ValueMember = "VrabotenID";


       }


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>