以文本方式查看主题
- Foxtable(狐表) (http://foxtable.com/bbs/index.asp)
-- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2)
---- 关于ListView的显示问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=133192)
|
-- 作者:hongyefor
-- 发布时间:2019/4/9 13:57:00
-- 关于ListView的显示问题
此主题相关图片如下:wt11.jpg
此主题相关图片如下:wt12.jpg
我有一个窗口,名为窗口1,里面有4个控件 其中有一个ListView的控件
我需要将表里的规格“S,M,L”作为ListView里的列显示,(“S,M,L”非固定的数据,有可能是“F”,也有可能是“XS,S,M,L,XL”等),箱号列也会有不同如果连续的箱号,装的款号一样,颜色一样,规格一样则箱号合并,比如说1号箱和2号箱装的款号一样,颜色一样,规格一样,则显示为1~2,不连续的则分开
请问这个代码怎么写
|
-- 作者:有点甜
-- 发布时间:2019/4/9 15:37:00
--
参考代码
Dim cj As WinForm.ComboBox = e.Form.Controls("ComboBox1") Dim dm As WinForm.ComboBox = e.Form.Controls("ComboBox2") If cj.text <> Nothing AndAlso dm.text <> Nothing Then Dim dt As DataTable = DataTables("箱单数据") Dim drs = dt.Select("款号 = \'" & dm.Text & "\'and 合同号 like \'%" & cj.Text & "%\'", "_sortkey") Dim ggs = dt.GetValues("规格", "款号 = \'" & dm.Text & "\'and 合同号 like \'%" & cj.Text & "%\'", "_sortkey") Dim lvw As WinForm.ListView = e.Form.Controls("ListView1") lvw.StopRedraw() \'暂停绘制 lvw.Columns.Clear() \'清除原来的列 lvw.Rows.Clear() \'清除原来的行 lvw.View = ViewMode.Details \'显示模式为详细信息 lvw.GridLines = True \'显示网格线 Dim cls() As String = {"颜色","箱号"} \'定义列名 Dim wds() As String = {120,100} \'定义列宽 For i As Integer = 0 To cls.Length - 1 \'增加列 Dim c As WinForm.ListViewColumn = lvw.Columns.Add() c.Text = cls(i) \'指定列标题 c.Name = cls(i) \'指定列名 c.Width = wds(i) \'指定列宽 Next For Each gg As String In ggs Dim c As WinForm.ListViewColumn = lvw.Columns.Add() c.Text = gg c.Name = gg c.Width = 20 Next cls = new String() {"箱数","数量"} \'定义列名 wds = new String() {40,40} \'定义列宽 For i As Integer = 0 To cls.Length - 1 \'增加列 Dim c As WinForm.ListViewColumn = lvw.Columns.Add() c.Text = cls(i) \'指定列标题 c.Name = cls(i) \'指定列名 c.Width = wds(i) \'指定列宽 Next Dim pdr As DataRow = Nothing Dim xs As Double = 0 Dim xhs As String = "" Dim sl As Double = 0 Dim pr As object = Nothing For Each dr As DataRow In drs If pdr Is Nothing OrElse pdr("规格") <> dr("规格") OrElse pdr("颜色") <> dr("颜色") Then If pr IsNot Nothing Then pr("箱号") = xhs.trim(",") pr(pdr("规格")) = "√" pr("箱数") = xs pr("数量") = sl End If Dim r As WinForm.ListViewRow = lvw.Rows.Add() \'增加一行 r("颜色") = dr("颜色") xhs = dr("箱号") xs = 1 sl = dr("数量") pr = r Else xhs &= "," & dr("箱号") xs += 1 sl += dr("数量") End If pdr = dr Next If pr IsNot Nothing Then pr("箱号") = xhs.trim(",") pr(pdr("规格")) = "√" pr("箱数") = xs pr("数量") = sl End If lvw.ResumeRedraw End If
|
-- 作者:hongyefor
-- 发布时间:2019/4/9 16:22:00
--
箱子里的数字不一样也需要分开,还有不要"√",需要实际的每箱数量,也就是如果有一箱数字不一样也需要分开的,还有如果是箱号1-2-3,那直接变为1-3
[此贴子已经被作者于2019/4/9 16:24:32编辑过]
|
-- 作者:有点甜
-- 发布时间:2019/4/9 18:11:00
--
请看懂代码,理解代码以后,自己修改。示例代码已经写出来给你。自己改动一下。
|
-- 作者:hongye
-- 发布时间:2019/4/12 22:52:00
--
Dim cj As WinForm.ComboBox = e.Form.Controls("ComboBox1") Dim dm As WinForm.ComboBox = e.Form.Controls("ComboBox2") If cj.text <> Nothing AndAlso dm.text <> Nothing Then Dim dt As DataTable = DataTables("箱单数据") Dim drs = dt.Select("款号 = \'" & dm.Text & "\'and 合同号 like \'%" & cj.Text & "%\'", "_sortkey") Dim ggs = dt.GetValues("规格", "款号 = \'" & dm.Text & "\'and 合同号 like \'%" & cj.Text & "%\'", "_sortkey") Dim lvw As WinForm.ListView = e.Form.Controls("ListView1") lvw.StopRedraw() \'暂停绘制 lvw.Columns.Clear() \'清除原来的列 lvw.Rows.Clear() \'清除原来的行 lvw.View = ViewMode.Details \'显示模式为详细信息 lvw.GridLines = True \'显示网格线 Dim cls() As String = {"颜色","箱号"} \'定义列名 Dim wds() As String = {120,100} \'定义列宽 For i As Integer = 0 To cls.Length - 1 \'增加列 Dim c As WinForm.ListViewColumn = lvw.Columns.Add() c.Text = cls(i) \'指定列标题 c.Name = cls(i) \'指定列名 c.Width = wds(i) \'指定列宽 Next For Each gg As String In ggs Dim c As WinForm.ListViewColumn = lvw.Columns.Add() c.Text = gg c.Name = gg c.Width = 30 Next cls = new String() {"箱数","数量"} \'定义列名 wds = new String() {40,40} \'定义列宽 For i As Integer = 0 To cls.Length - 1 \'增加列 Dim c As WinForm.ListViewColumn = lvw.Columns.Add() c.Text = cls(i) \'指定列标题 c.Name = cls(i) \'指定列名 c.Width = wds(i) \'指定列宽 Next Dim pdr As DataRow = Nothing Dim xs As Double = 0 Dim xhs As String = "" Dim sl As Double = 0 Dim pr As object = Nothing For Each dr As DataRow In drs If pdr Is Nothing OrElse pdr("规格") <> dr("规格") OrElse pdr("颜色") <> dr("颜色") OrElse pdr("数量") <> dr("数量")Then If pr IsNot Nothing Then pr("箱号") = xhs.trim("-") pr(pdr("规格")) = dr("数量") pr("箱数") = xs pr("数量") = sl End If Dim r As WinForm.ListViewRow = lvw.Rows.Add() \'增加一行 r("颜色") = dr("颜色") xhs = dr("箱号") xs = 1 sl = dr("数量") pr = r Else xhs &= "-" & dr("箱号") xs += 1 sl += dr("数量") End If pdr = dr Next For Each dr As DataRow In drs If pr IsNot Nothing Then pr("箱号") = xhs.trim("-") pr(pdr("规格")) = dr("数量") pr("箱数") = xs pr("数量") = sl End If Next lvw.ResumeRedraw End If
此主题相关图片如下:问题.jpg
怎么显示的数据错误?
|
-- 作者:有点蓝
-- 发布时间:2019/4/12 23:21:00
--
…… For Each dr As DataRow In drs If pdr Is Nothing OrElse pdr("规格") <> dr("规格") OrElse pdr("颜色") <> dr("颜色") OrElse pdr("数量") <> dr("数量")Then If pr IsNot Nothing Then pr("箱号") = xhs.trim("-") pr(pdr("规格")) = pdr("数量") pr("箱数") = xs pr("数量") = sl End If Dim r As WinForm.ListViewRow = lvw.Rows.Add() \'增加一行 r("颜色") = dr("颜色") xhs = dr("箱号") xs = 1 sl = dr("数量") pr = r Else xhs &= "-" & dr("箱号") xs += 1 sl += dr("数量") End If pdr = dr Next If drs.count > 0 Dim dr = drs(drs.count - 1) If pr IsNot Nothing Then pr("箱号") = xhs.trim("-") pr(pdr("规格")) = dr("数量") pr("箱数") = xs pr("数量") = sl End If End If lvw.ResumeRedraw End If
|
-- 作者:hongyefor
-- 发布时间:2019/4/13 11:24:00
--
Dim cj As WinForm.ComboBox = e.Form.Controls("ComboBox1") Dim dm As WinForm.ComboBox = e.Form.Controls("ComboBox2") If cj.text <> Nothing AndAlso dm.text <> Nothing Then Dim dt As DataTable = DataTables("箱单数据") Dim drs = dt.Select("款号 = \'" & dm.Text & "\'and 合同号 like \'%" & cj.Text & "%\'", "_sortkey") Dim ggs = dt.GetValues("规格", "款号 = \'" & dm.Text & "\'and 合同号 like \'%" & cj.Text & "%\'", "_sortkey") Dim lvw As WinForm.ListView = e.Form.Controls("ListView1") lvw.StopRedraw() \'暂停绘制 lvw.Columns.Clear() \'清除原来的列 lvw.Rows.Clear() \'清除原来的行 lvw.View = ViewMode.Details \'显示模式为详细信息 lvw.GridLines = True \'显示网格线 Dim cls() As String = {"颜色","箱号"} \'定义列名 Dim wds() As String = {120,70} \'定义列宽 For i As Integer = 0 To cls.Length - 1 \'增加列 Dim c As WinForm.ListViewColumn = lvw.Columns.Add() c.Text = cls(i) \'指定列标题 c.Name = cls(i) \'指定列名 c.Width = wds(i) \'指定列宽 Next For Each gg As String In ggs Dim c As WinForm.ListViewColumn = lvw.Columns.Add() c.Text = gg c.Name = gg c.Width = 30 Next cls = new String() {"箱数","数量"} \'定义列名 wds = new String() {40,40} \'定义列宽 For i As Integer = 0 To cls.Length - 1 \'增加列 Dim c As WinForm.ListViewColumn = lvw.Columns.Add() c.Text = cls(i) \'指定列标题 c.Name = cls(i) \'指定列名 c.Width = wds(i) \'指定列宽 Next Dim pdr As DataRow = Nothing Dim xs As Double = 0 Dim xhs As String = "" Dim sl As Double = 0 Dim pr As object = Nothing For Each dr As DataRow In drs If pdr Is Nothing OrElse pdr("规格") <> dr("规格") OrElse pdr("颜色") <> dr("颜色") OrElse pdr("数量") <> dr("数量")Then If pr IsNot Nothing Then pr("箱号") = xhs.trim("-") pr(pdr("规格")) = pdr("数量") pr("箱数") = xs pr("数量") = sl End If Dim r As WinForm.ListViewRow = lvw.Rows.Add() \'增加一行 r("颜色") = dr("颜色") xhs = dr("箱号") xs = 1 sl = dr("数量") pr = r Else xhs &= "-" & dr("箱号") xs += 1 sl += dr("数量") End If pdr = dr Next If drs.count > 0 Dim dr = drs(drs.count - 1) If pr IsNot Nothing Then pr("箱号") = xhs.trim("-") pr(pdr("规格")) = dr("数量") pr("箱数") = xs pr("数量") = sl End If End If lvw.ResumeRedraw End If
此主题相关图片如下:wt12.jpg
请问如何去掉图片中连续箱号中间的数字,让它只显示头箱和尾箱。也就是如果是4-5-6-7-8装箱数颜色规格一样的同类产品,只显示 4-8 ,表示第4箱到第8箱的数量规格颜色一致
|
-- 作者:有点蓝
-- 发布时间:2019/4/13 11:42:00
--
Dim str As String = "4-5-6-7-8" Dim arr() As String = str.split("-") msgbox(arr(0) & "-" & arr(arr.length - 1))
|
-- 作者:hongyefor
-- 发布时间:2019/4/13 12:14:00
--
不知道加哪里
|
-- 作者:有点蓝
-- 发布时间:2019/4/13 13:50:00
--
For Each dr As DataRow In drs If pdr Is Nothing OrElse pdr("规格") <> dr("规格") OrElse pdr("颜色") <> dr("颜色") OrElse pdr("数量") <> dr("数量")Then If pr IsNot Nothing Then pr("箱号") = xhs.trim("-") pr(pdr("规格")) = pdr("数量") pr("箱数") = xs pr("数量") = slDim arr() As String = pdr("箱号").split("-") if arr.length > 2 pdr("箱号") = arr(0) & "-" & arr(arr.length - 1) end if End If Dim r As WinForm.ListViewRow = lvw.Rows.Add() \'增加一行 r("颜色") = dr("颜色") xhs = dr("箱号") xs = 1 sl = dr("数量") pr = r Else xhs &= "-" & dr("箱号") xs += 1 sl += dr("数量") End If pdr = dr Next
|