vb.net如何显示可变列宽的数据列表? [英] vb.net how to show list of data with variable column widths?

查看:138
本文介绍了vb.net如何显示可变列宽的数据列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里我试图从一个窗口形式的ADODB记录填写一个ListView(或其他控件)的数据的情况。问题是最行将具有几列,但有些行只会有1列。我想创建一个POS解决方案,其中部分线路可以评论。
例如输出(简化为简洁起见):结果

I have a situation where I'm trying to fill a listview (or other control) with data from an ADODB recordset in a windows form. The problem is most rows will have several columns, but some rows will only have 1 column. I am trying to create a POS solution where some lines can be comments. example output (simplified for brevity):

第1行:[数量1],[ITEM1],[ITEM1说明],[ITEM1价格]结果
2号线:[注释1]结果
3号线:​​[quantity2],[ITEM2],[ITEM2说明],[ITEM2价格]结果
4号线:[quantity3],[项目3],[项目3描述],[项目3价格]结果
5号线:[注释2]

line 1: [quantity1], [item1], [item1 description], [item1 price]
line 2: [comment1]
line 3: [quantity2], [item2], [item2 description], [item2 price]
line 4: [quantity3], [item3], [item3 description], [item3 price]
line 5: [comment2]

我想注释行跨越控制的整个宽度。
这是我的理解是一个ListView不会允许可变列宽这样。有没有在vb.net windows窗体控件,将允许这种类型的格式?还是有实现这一目标的视觉输出的任何其他方式?

I would like the comment rows to span the entire width of the control. It is my understanding that a listview will not allow variable column widths like this. Is there a control in vb.net windows forms that will allow this type of formatting? Or is there any other way of achieving this visual output?

推荐答案

我终于找到了一个自定义DataGridView控件这里从该viblend伟大工程。
我还在寻找新的控制绳索,但我可以通过以下code合并对飞行:

I finally found a custom datagridview control here from viblend that works great. I'm still finding the ropes with the new control, but I'm able to merge rows on the fly through the following code:

    Imports VIBlend.WinForms.DataGridView
    Imports VIBlend.Utilities

    Public Class Form1
        Private Sub Form1_Shown(sender As System.Object, e As System.EventArgs) Handles MyBase.Shown
            With viDataGridView1
                .AutoGenerateColumns = True
                'dt is a pre-defined dataTable variable
                .DataSource = dt
                .ColumnsHierarchy.AutoResize()
                'dataTable has 9 columns, first and last columns should be invisible
                'unless the row is a designated row for comments
                .ColumnsHierarchy.Items(0).Width = 0 'this column contains string comment, empty string for non-comment rows
                .ColumnsHierarchy.Items(8).Width = 0 'this column contains boolean flag [isComment]
                .AllowCellMerge = True
                .Refresh()
            End With
        End Sub

        Private Sub viDataGridView1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) _
                                        Handles viDataGridView1.Paint
            Dim colItem As HierarchyItem
            With viDataGridView1
                For Each rowItem In .RowsHierarchy.Items
                    colItem = .ColumnsHierarchy.Items(8) 'column with boolean flag
                    If .CellsArea.GetCellValue(rowItem, colItem).Equals(True) Then
                        'this is a comment line
                        colItem = .ColumnsHierarchy.Items(0)
                        .CellsArea.SetCellSpan(rowItem, colItem, 1, 7)
                    End If
                Next
            End With
        End Sub
    End Class

这篇关于vb.net如何显示可变列宽的数据列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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