Devexpress Xtragrid TileView

时间:2016-08-31 06:21:39

标签: devexpress xtragrid

我正在使用Devexpress Xtragrid TileView模块。

基本上我希望我的代码可以这样工作:

  1. 左上方文本框中的用户输入成员ID,然后按加载。
  2. 如果它们存在,那么就会出现一个瓷砖。
  3. 图块应包含:名称,状态,会员ID和照片。
  4. 如果用户再次按下加载(相同的ID或其他ID),也会添加Tile,依此类推。除非他们按Clear&加载,它应该只剩下1个最新的瓷砖。
  5. 所以,我能够完成第3步。 但我无法加载图片。

    图片本身,它不是字节数组。它是一个图像路径。 e.q:D:/test/1.jpg

    那么,我该如何加载图片?

    Protected Overridable Sub InitData()
        Try
            Dim homesTable = ds.Tables(0)
            homesTable.Columns.Add("ImageCol")
    
            For Each row_Renamed As DataRow In homesTable.Rows
                Dim img As Image = Image.FromFile(row_Renamed("memberPhoto")) 'I tried this, but didn't work
                row_Renamed("ImageCol") = img
            Next row_Renamed
    
            GridControl1.DataSource = homesTable
        Catch
        End Try
    End Sub
    
    Private Sub setupTile()
        'For i = 0 To j - 1
        Try
            TileView1.BeginUpdate()
            'TileView1.DataSource = ds.Tables(0)
            TileView1.OptionsTiles.RowCount = 3
            TileView1.OptionsTiles.Padding = New Padding(20)
            TileView1.OptionsTiles.ItemPadding = New Padding(10)
            TileView1.OptionsTiles.IndentBetweenItems = 20
            TileView1.OptionsTiles.ItemSize = New Size(320, 170)
            TileView1.Appearance.ItemNormal.ForeColor = Color.White
            TileView1.Appearance.ItemNormal.BorderColor = Color.Transparent
            'Setup tiles template
            Dim leftPanel As New TileViewItemElement()
            Dim splitLine As New TileViewItemElement()
            Dim nameCaption As New TileViewItemElement()
            Dim nameValue As New TileViewItemElement()
            Dim statusCaption As New TileViewItemElement()
            Dim statusValue As New TileViewItemElement()
            Dim RGPCaption As New TileViewItemElement()
            Dim RGPvalue As New TileViewItemElement()
            Dim imageTile As New TileViewItemElement()
            TileView1.TileTemplate.Add(leftPanel)
            TileView1.TileTemplate.Add(splitLine)
            TileView1.TileTemplate.Add(nameCaption)
            TileView1.TileTemplate.Add(nameValue)
            TileView1.TileTemplate.Add(statusCaption)
            TileView1.TileTemplate.Add(statusValue)
            TileView1.TileTemplate.Add(RGPCaption)
            TileView1.TileTemplate.Add(RGPvalue)
            TileView1.TileTemplate.Add(imageTile)
            '
            'nameValue.Text = ""
            'statusValue.Text = ""
            'RGPvalue.Text = ""
            'imageTile.Image = Nothing
    
            '
            leftPanel.StretchVertical = True
            leftPanel.Width = 190
            leftPanel.TextLocation = New Point(-10, 0)
            leftPanel.Appearance.Normal.BackColor = Color.FromArgb(58, 166, 101)
            '
            splitLine.StretchVertical = True
            splitLine.Width = 3
            splitLine.TextAlignment = TileItemContentAlignment.Manual
            splitLine.TextLocation = New Point(190, 0)
            splitLine.Appearance.Normal.BackColor = Color.White
            '
            nameCaption.Text = "Name"
            nameCaption.TextAlignment = TileItemContentAlignment.TopLeft
            nameCaption.Appearance.Normal.FontSizeDelta = -1
            '
            nameValue.Column = TileView1.Columns("preferredName")
            nameValue.AnchorElement = nameCaption
            nameValue.AnchorIndent = 2
            nameValue.MaxWidth = 200
            nameValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
            'nameValue.Text = ds.Tables(0).Rows(i)("preferredName").ToString
            '
            statusCaption.Text = "Status"
            statusCaption.AnchorElement = nameValue
            statusCaption.AnchorIndent = 14
            statusCaption.Appearance.Normal.FontSizeDelta = -1
            '
            statusValue.Column = TileView1.Columns("memberStatus")
            statusValue.AnchorElement = statusCaption
            statusValue.AnchorIndent = 2
            statusValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
            'statusValue.Text = ds.Tables(0).Rows(i)("memberStatus").ToString
            '
            RGPCaption.Text = "RGP"
            RGPCaption.AnchorElement = nameValue
            RGPCaption.AnchorIndent = 65
            'RGPCaption.TextLocation
            'RGPCaption.Appearance.Normal.FontSizeDelta = -1
            RGPCaption.Appearance.Normal.Font = New Font("Segoe UI Semibold", 12.0F, System.Drawing.FontStyle.Regular)
            '
            RGPvalue.Column = TileView1.Columns("code")
            RGPvalue.AnchorElement = RGPCaption
            RGPvalue.AnchorIndent = 1
            RGPvalue.TextAlignment = TileItemContentAlignment.BottomLeft
            RGPvalue.Appearance.Normal.Font = New Font("Segoe UI Semilight", 25.75F, System.Drawing.FontStyle.Regular)
            'RGPvalue.Text = ds.Tables(0).Rows(i)("code").ToString
            '
            imageTile.Column = TileView1.Columns("ImageCol")
            imageTile.ImageSize = New Size(120, 170)
            imageTile.ImageAlignment = TileItemContentAlignment.MiddleRight
            imageTile.ImageScaleMode = TileItemImageScaleMode.Stretch
            imageTile.ImageLocation = New Point(12, 0)
    
        Catch ex As Exception
            XtraMessageBox.Show(ex.Message)
        Finally
            TileView1.EndUpdate()
        End Try
        'Next
    
    
    End Sub
    
    Private Sub loadBtn_Click(sender As Object, e As EventArgs) Handles loadBtn.Click
            initData()
            setupTile()
    End Sub
    

    UI

1 个答案:

答案 0 :(得分:0)

可能为时已晚,但在我的情况下,只需要从磁盘读取文件并分配到byte()列。

首先,表列应该是字节数组,所以替换:

CI=true TRAVIS=true CONTINUOUS_INTEGRATION=true

有:

homesTable.Columns.Add("ImageCol")

然后我试着替换:

homesTable.Columns.Add(New DataColumn("ImageCol", GetType(Byte)))

有:

row_Renamed("ImageCol") = img

这会将磁盘文件加载到字节数组并显示在tile中。我检查文件是否存在以避免异常。

这是我从磁盘加载图片的方法。

希望它有所帮助。