Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a combobox in datagridview,successfully adding the record into db and storing the combobox id(value member)value into db.I am using search button to dispaly that saved values into datagridview.
Ex:
combo box column:
display members: A,B,C(Prod)
Value Memeber:1,2,3(ID)

Table:---
ID Date Prod
2 7/26/2012 B
3 7/27/2012 C
2 7/27/2012 B
1 7/28/2012 A


when search from 7/26/2012 to 7/27/2012, Datagridview display the 3 records:

my Datagridview consists Combobox-(Products),textbox(Date)
i am displaying the products in combobox and date in textbox

Products Date

B 7/26/2012
C 7/27/2012
B 7/27/2012


any one please send the code


Thanks in advance
Sucharitha
Posted
Updated 30-Jul-12 19:32pm
v10
Comments
Menon Santosh 27-Jul-12 8:24am    
please elaborate

1 solution

Query the DB
C#
sql="Select uID,cUnit from tblUnit";


Now add a combo column in datagridview and pass datatable
C#
public  void AddColumnCombo(DataGridView Grid, string sCaption, DataTable dt, string sDisplayMember, string sValueMember)
        {
           
            DataGridViewComboBoxColumn GColumn = new DataGridViewComboBoxColumn
            {
                HeaderText = sCaption,
                DataSource = dt,
                DisplayMember = sDisplayMember,
                ValueMember = sValueMember
            };            
            Grid.Columns.Add(GColumn);            
            
        }




now asign the value to set required data for eg set 2 to display B

C#
DataGridView[0,0].Value = Convert.ToString(datarow["UId"]) == "" ? null : (object)Convert.ToInt32(datarow["UId"]);
 
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