Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i have a combobox having items(suresh,ramesh,naresh) inside the datagridview.

in my database saving ramesh.

reading correctly but i don't know how can i bind the combobox(giving selectedindex=1).

can any body solve this.


thanks in advance..........
Posted
Updated 7-Feb-18 20:30pm
v2
Comments
AshishChaudha 6-Aug-12 6:53am    
What you have done so far..??? Exactly what you want to do??
U@007 6-Aug-12 6:58am    
this is not web application
it's windows application

C#
string str="select id,name from tbl";
//fetch datatable using sql-connection and data-adapter
da.fill(dt);
combobox1.Datasource=dt;
combobox1.DisplayMember="name";
combobox1.ValueMember="id";
combobox1.Refresh();



for grid view
C#
If (dgv.currentcell.ColumnIndex==2) //2nd is combobox column
{
   datagridViewComboboxCell combobox1 = Directcast(dgv.currentcell,datagridViewComboboxCell);
   //   Now use above code here 
}


Happy Coding!
:)
 
Share this answer
 
v3
Comments
U@007 6-Aug-12 7:32am    
hello aarti combobox1 is inside the datagridview.
ok
Go to the ItemDataBound event of gridview and find your ComboBox control and set the DataSource, DataTextField and DataValueField as Aarti said in Solution 2.



--Amit
 
Share this answer
 
Finally i did this

C#
if (datagridview1.Rows.Count != 0)
  {
      for (int i = 0; i < datagridview1.Rows.Count; i++)
      {

          datagridview1.Rows[i].Cells["Type"].Value = "DatabaseValue";

      }

  }
 
Share this answer
 
v2

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