Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
//here is my databinding code
C#
public void FillCheckedListBox1party()
        {
           try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }

                string commandString = "SELECT NAME ,AC_CODE FROM AccountM where compcode='" + Compcls.Gcomp_cd + "'";
               
                DataTable accTable = new DataTable();
                SqlCommand cmd = new SqlCommand(commandString, con);
                SqlDataAdapter adpObj = new SqlDataAdapter(cmd);
                accTable.TableName = "tbl";
                adpObj.Fill(accTable);
                con.Close();
                checkedListBox1.DataSource = accTable;
                checkedListBox1.ValueMember = "AC_CODE";
                checkedListBox1.DisplayMember ="NAME";
                checkedListBox1.BindingContext = new BindingContext();
                // myChkListBox.BindingContext = new BindingContext(); 
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                con.Close();
            }
        }


thanks in advanced


lakhan

[edit]SHOUTING removed, Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]
Posted
Updated 31-Dec-11 3:02am
v5
Comments
OriginalGriff 31-Dec-11 4:37am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
[no name] 31-Dec-11 4:38am    
ok i will
[no name] 31-Dec-11 9:04am    
And what is the problem you are having?
[no name] 2-Jan-12 0:51am    
actually i want to get ValueMember in StringBuilder here is my code can u help me.....if (con.State == ConnectionState.Closed)
{
con.Open();
}
StringBuilder query = new StringBuilder("SELECT ITEMCODE, BROKTYPE,BROKRATE,TRANRATE,TranType,uptostdt,MARTYPE,MARRATE FROM PITBROK ");
query.AppendFormat("where ");
for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
{
int coun = checkedListBox1.CheckedItems.Count;
coun = coun - 1;

query.AppendFormat("PITBROK.AC_CODE='{0}' ", checkedListBox1.CheckedItems[value]);

if (i < coun)
{
query.AppendFormat(" and ");
}
[no name] 2-Jan-12 0:53am    
query.AppendFormat("PITBROK.AC_CODE='{0}' ", checkedListBox1.CheckedItems[value]); in this line what change i have to do ?? to get valuemember of all checked item in checkedlistbox1

C#
if(checkedListBox1 .CheckedItems.Count>0)
                        {
                        DataRow row;
               row = ((DataRowView) this.checkedListBox1.CheckedItems[i]).Row;
            val= (row[this.checkedListBox1.ValueMember]).ToString();
     row = null;
 
                              query.AppendFormat("PITBROK.AC_CODE='{0}' ", val.ToString());
 
Share this answer
 
v2
Comments
Anuja Pawar Indore 3-Jan-12 9:10am    
is this your solution. If not then paste it is your question, use improve question link
[no name] 3-Jan-12 9:21am    
ya you are right ,i was wrong .....
[no name] 3-Jan-12 9:22am    
if u can help me than please here my question link .....
http://www.codeproject.com/Questions/309690/how-to-get-combobox-in-datagridview-current-cell-o
Hi sanoth,

Bind CheckedListBOx or any other control with displaymember and valuemember is quite simple you just need to specify datasource property of control as well as displaymember and valuemember.


Following is working code 100 % work for me i have tested:P

/* checkedlistbox bindig code */

DataSet ds = new DataSet();

string strChechboxlist = "select Subject_ID as code, SubjectName as Display from dbo.Mst_Subject_Detail";

/* filldataset() is function i have created to return dataset. */
ds = dc.FillDataSet(strChechboxlist);
if (ds.Tables[0].Rows.Count > 0)
{
checkedListBox1.DataSource = ds.Tables[0];
checkedListBox1.DisplayMember = "Display";
checkedListBox1.ValueMember = "code";

}

/* for fetching valuemember or displaymember from checkedlistbox */


for(int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
{

/*Now with the following code we can get valemember and displaymember as per your requirement you can store in table. */
DataRow r;
r = ((DataRowView)this.checkedListBox1.CheckedItems[i]).Row;
string val = (r[this.checkedListBox1.ValueMember]).ToString();
string dis = (r[this.checkedListBox1.DisplayMember]).ToString();
r = null;

}


Note :- I am attaching working demo of code
 
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