Click here to Skip to main content
15,902,721 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi In my Program one list box is there.How i can save the multiple selected items in database.
Posted

Hi,

You can do as follows.

By using for loop,you can solve this issue.

for(int i=0;i<listbox.items.count;i++)>
{
   string strselecteditems=listbox.selectedItems[i].Text;

   //Call the database function.
}


or you can do the following way also.

string strtemp="";

C#
for(int i=0;i<listbox.items.count;i++)
{
     
     string strselecteditems=listbox.selectedItems[i].Text;
strtemp=strtemp + ","+ strselecteditems
   
}


After getting selected items in strtemp varaiable,then cal the database fucntion.

Regards,
Kiran.
 
Share this answer
 
Comments
rohith1750 16-Feb-11 4:57am    
If i do like above then order by listbox values are saved but not selected values are saved.
Member 14277791 17-Apr-19 7:37am    
how to display multiselected listbox items into a label.
string strtemp = "";
for(int i=0;i<listbox.selecteditems.count;i++)>
{
     strtemp=strtemp + ","+ listbox.selectedItems[i].Text;
}

And then split strtemp, you'll get all selected items. :)
 
Share this answer
 
v2
Here my solution

For C/C++ you have to use a double tabled declaration.

When you receive the Windows on message it should be like that on the receive part of your program

First clean your config memory and after refresh according the GUI should be like that in your code :


C#
void CMyDlg::OnChangeListDB()
{
int buf[10];
int;
int len;
if (!myConfiguration.Mode) 
    {
    len = m_listdb.GetSelItems(10,buf);
    for (i = 0; i<10; i++)
        {
        myConfiguration.Everything[i] = 0;
        }
    for(i=0;i<len;i++)>
        {
        myConfiguration.Everything[buf[i]] = 1;
        }
    }
else 
    {
    len = m_listdb.GetSelItems(6,buf);
    for (i = 0; i< 6; i++)
        {
        myConfiguration.Other[i] = 0;
        }
    for(i=0;i<len;i++)
        {
        myConfiguration.Other[buf[i]] = 1;
        }
    }
 
Share this answer
 
Hi,

Add one more condition in for loop as follows.

C#
for(int i=0;i<listbox.items.count;i++)
{
     if(listbox.selectedItems[i].selected==true)
{
     string strselecteditems=listbox.selectedItems[i].Text;
strtemp=strtemp + ","+ strselecteditems
}
}


It will help you.

Regards,
Kiran.
 
Share this answer
 
Comments
nagendrathecoder 16-Feb-11 5:06am    
It'll give error inside for loop.
This will work only if all items are selected.

If you are using SelectedItems property then no need to check with Selected property.

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