sammi taylor

sammi taylor

  • NA
  • 19
  • 0

datagridview displays ID not name value

Apr 17 2015 11:45 AM
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; }  
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.
 

Answers (1)