ListBox多个选定项目保存在数据库中 [英] ListBox multiple selected items saving in database

查看:58
本文介绍了ListBox多个选定项目保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 在我的程序中,有一个列表框.如何将多个选定项保存到数据库中.

解决方案



您可以执行以下操作.

通过使用for循环,可以解决此问题.

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

   //Call the database function.
}



或者您也可以按照以下方式进行操作.

字符串strtemp =";

  for ( int  i =  0 ; i< listbox.items.count; i ++)
{
     
     字符串 strselecteditems = listbox.selectedItems [i] .Text;
strtemp = strtemp + "  + strselecteditems
   
} 



在获得 strtemp 变量中的选定项目之后,请计算数据库功能.

问候,
Kiran.


string strtemp = "";
for(int i=0;i<listbox.selecteditems.count;i++)>
{
     strtemp=strtemp + ","+ listbox.selectedItems[i].Text;
}


然后拆分strtemp,您将获得所有选定的项目. :)


这是我的解决方法

对于C/C ++,您必须使用双表声明.

当您收到Windows on消息时,它应该类似于程序的接收部分上的消息

首先清理您的配置内存,然后根据GUI刷新后应与您的代码中的类似:


  void  CMyDlg :: OnChangeListDB()
{
 int  buf [ 10 ];
 int ;
 int  len;
如果(!myConfiguration.Mode)
    {
    len = m_listdb.GetSelItems( 10 ,buf);
     for (i =  0 ; i< 10; i ++)
        {
        myConfiguration.Everything [i] =  0 ;
        }
     (i =  0 ; i< len; i ++) > 
        {
        myConfiguration.Everything [buf [i]] =  1 ;
        }
    }
其他
    {
    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 ;
        }
    } 


hi In my Program one list box is there.How i can save the multiple selected items in database.

解决方案

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="";

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.


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. :)


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 :


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;
        }
    }


这篇关于ListBox多个选定项目保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆