Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have created a combox and add it to the datagridviewcell .when i select the value from the combox .the selected value is not displayed on that cell.if i move on to next cell.if anyone knows how to store the combobox selected value in datagridview
cell.

help me.
Posted
Comments
praveenkumar78 30-Mar-12 6:43am    
thanks for your suggestion.
actually i can able to bind the value to combobox .when i select the value
from that combobox the selected value will not be displayed when i move to
the next cell.here is my code

public ComboBox combobox2 = new ComboBox();
private void hmloadingpage1_Load(object sender, EventArgs e)
{

combobox2.Hide();
dataGridView1.Controls.Add(combobox2);

}


private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
this.combobox2.Location = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location;
this.combobox2.SelectedValue = this.dataGridView1.CurrentCell.Value;
this.combobox2.Show();
dataGridView1.Rows[e.RowIndex].Cells[2].Value = this.combobox2.Text.ToString();


}
ProEnggSoft 30-Mar-12 7:12am    
From the code it seems that you are using the ComboBox control. But for displaying the ComboBox within the DataGridView, DataGridViewComboBoxColumn control is to be used as given in the example at the link shown in Solution 1. Further after setting the DisplayMember and ValueMember properties of DataGridViewComboBoxColumn the values will be automatically set. The values need not be set manually.

1 solution

The DisplayMember and ValueMember properties of the DataGridViewComboBoxColumn are to be set appropriately like
C#
comboboxColumn.DataSource = RetrieveAlternativeTitles();
comboboxColumn.ValueMember = ColumnName.TitleOfCourtesy.ToString();
comboboxColumn.DisplayMember = comboboxColumn.ValueMember;

as given here
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx#Y3747[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900