I encounter a problem regarding the deleting of data using combo box. The error prompted me I have no idea of how to solve it. Anyone can help me about it?
priva
I think you put your code in wrong place..
you just add items on same combo select change (cbLocationData_SelectedIndexChanged)
that's wrong
put your code other appropriate place in which adding items are not part of same events
Your event is firing on SelectedindexChanged of the cb you're trying to fill. Try putting it in the page load or a more appropriate place?
Create a method something like this:
private void LoadLocation()
{
using (testEntities Setupctx = new testEntities())
{
var storeLocation = (from vL in Setupctx.locations
select new
{
Location1 =vL.Location1
}
);
cbLocationData.DataTextField = "Location1";
cbLocationData.DataSource = storeLocation;
cbLocationData.DataBind();
}
}
Then on your page load(asp.net)/form Load(winform) add:
LoadLocation();
Hope this help.
Regards
private void cbLocationData_SelectedIndexChanged(object sender, EventArgs e)
{
using (testEntities Setupctx = new testEntities())
{
var storeLocation = (from vL in Setupctx.locations
where vL.Location1 == vL.Location1
select vL.Location1);
foreach (var locationData in storeLocation)
{
cbLocationData.Items.Add(locationData.ToString());
}
}
}
Is it possible that locationData needs set to tostring() or convert(), depending on the data type? Everything looks like it should be working correctly.