I have VS2012, Winform app. In my Search form, I do a search via txtbox & cboboxes where my dropdown list display all names, which is correct binding. But once I click btnSearch, my datagridviewtextboxColumn displays the correct ID, not the name. I manually binded my controls to the dgv with a bindingsource. how do I display the name that is correct in my cbobox, to also display in my dgv column?
Searchdgv:
column: InvestigatorID
datapropertyName: InvestigatorID
columnType: datagridviewtextboxColumn
InvestigatorBLL property:
public int? ID {get; set; }
private void btnSearch_Click(object sender, EventArgs e)
{
BindData();
if (bindingSource1.Count <= 0)
{
MessageBox.Show("No results returned. Clear your search and enter a new case.");
return;
}
dgvSearch.DataSource = bindingSource1;
}
public String DisplayName {get; set;}
public string DisplayValue {get { return DisplayName; } }
//PickListItemClass
public PicklistItem(IPickListItem item, bool enabled)
{
ID = item.ID;
Description = item.DisplayValue;
Enabled = enabled; }
//bind data
bindingSource1.DataSource = data;
dgvSearch.AutoGenerateColumns = false;
dgvSearch.DataSource = data.ToSortableBindingList();
private void btnSearch_Click(object sender, EventArgs e)
{
BindData();
if (bindingSource1.Count <= 0)
{
MessageBox.Show("No results returned. Clear your search and enter a new case.");
return;
}
dgvSearch.DataSource = bindingSource1;
}
How do I get my dgv to display name? InvestigatorName=John Doe; InvestigatorID=2. I need the name, but I get ID.
Thank you in advance.
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
sammi taylorPosted Apr 17, 2015, 10:26 PM