还有就是我的code这里的一个问题,有人可以看看吗? [英] There is an issue with my code here, can someone look?

查看:201
本文介绍了还有就是我的code这里的一个问题,有人可以看看吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有获取与五项填充列表视图框。这里的code,我用填充它。

 昏暗RS作为新ADODB.Recordset
设定RS =新ADODB.Recordset
昏暗lvwItem作为列表项
暗淡x As中整型lvwExpenditures.ListItems.Clear
    随着lvwExpenditures
        .FullRowSelect = TRUE
        .View = lvwReport
        .LabelEdit = lvwManual
        .ColumnHeaders.Add,FldName,费用,2200
        .ColumnHeaders.Add,ID,标识,0
    结束与
    g_strSQL =选择FldName,标识,标签,从SortOrder的,其中dbo.tblText_References = fldname'expenditureitems'
rs.Open g_strSQL,g_cnDatabase,ADOPENSTATIC
Debug.Print g_strSQL随着RS
  这样做虽然不.EOF
        设置lvwItem = lvwExpenditures.ListItems.Add(,点域(标签)。值)
        lvwItem.SubItems(1)=点域(ID)。值填充日期列
     .MoveNext
  循环

结束以

设置RS =什么

我试图做的是让用户选择多个项目,并置项目(用逗号),并将其插入表中。这里的code我有试图把选定的项目和将它们连接起来(我建了一个功能),但问题是,它需要的项目之一,并concatonates三次时(在列表视图中选择了三个项目)。我将展示标签并保存ID,所以当列表视图是按照这个顺序10,11,12,13,14加载ID走。在我的最后一次尝试,我选择了前三名的项目和功能,它转换为(13,13,13)。如何解决呢?我知道它的一个小问题。

 暗淡x As中整型
昏暗的myString作为字符串
当x = 1到lvwExpenditures.ListItems.Count
如果lvwExpenditures.ListItems(X)= .Selected true,那么
    如果x = 1,则
    了mystring = lvwExpenditures.SelectedItem.SubItems(1)
    其他
        myString的=的myString&安培; 与& lvwExpenditures.SelectedItem.SubItems(1)
    万一
其他万一
下一个x


解决方案

 暗淡x As中整型
昏暗的myString作为字符串
九月暗淡作为字符串
九月=,当x = 1到lvwExpenditures.ListItems.Count
    如果lvwExpenditures.ListItems(X).Selected然后
        myString的=的myString&安培; lvwExpenditures.ListItems(x)的.SubItems(1)及九月
    万一
下一个x如果了mystring<>中,然后
    了mystring =左(MyString的,LEN(MyString的)-len(SEP)
万一

I have a listview box that gets populated with five items. Here's the code that I used to populate it

Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
Dim lvwItem   As ListItem
Dim x As Integer

lvwExpenditures.ListItems.Clear
    With lvwExpenditures
        .FullRowSelect = True
        .View = lvwReport
        .LabelEdit = lvwManual
        .ColumnHeaders.Add , "FldName", "EXPENSES", 2200
        .ColumnHeaders.Add , "ID", "ID", 0
    End With


    g_strSQL = "Select FldName, ID, Label, SortOrder from  dbo.tblText_References where fldname ='expenditureitems'"
rs.Open g_strSQL, g_cnDatabase, adOpenStatic
Debug.Print g_strSQL

With rs
  Do While Not .EOF
        Set lvwItem = lvwExpenditures.ListItems.Add(, ,  .Fields("Label").Value)
        lvwItem.SubItems(1) = .Fields("ID").Value 'Populate Date column
     .MoveNext
  Loop

End With

Set rs = Nothing

What I'm trying to do is let the user select multiple items, concatenate the items (with a comma) and insert them into a table. Here's the code I have for trying to take the selected items and concatenate them (I built a function), but the issue is, it takes one of the items, and concatonates it three times (when three items were selected in listview). I show the label and save the ID, so the when listview is loaded the ID's go in this order 10,11,12,13,14. On my last try, I selected the top three items and the function converted it to (13,13,13). How do I fix it? I know its a small issue

dim x As Integer
Dim mystring As String
For x = 1 To lvwExpenditures.ListItems.Count
If lvwExpenditures.ListItems(x).Selected = True Then
    If x = 1 Then
    mystring = lvwExpenditures.SelectedItem.SubItems(1)
    Else
        mystring = mystring & "," & lvwExpenditures.SelectedItem.SubItems(1)
    End If
Else

End If
Next x

解决方案

dim x As Integer
Dim mystring As String
dim sep as string
sep=", "

For x = 1 To lvwExpenditures.ListItems.Count
    If lvwExpenditures.ListItems(x).Selected  Then
        mystring = mystring & lvwExpenditures.ListItems(x).SubItems(1) & sep
    End If
Next x

if mystring<>"" then
    mystring=left(mystring,len(mystring)-len(sep)
end if

这篇关于还有就是我的code这里的一个问题,有人可以看看吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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