UltraWinGrid手记

1、使某一列不能编辑

 grd2.DisplayLayout.Bands(0).Columns("还款金额").CellActivation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit

2、使某一单元格不能编辑

ultraGrid1.Rows(0).Cells(1).Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly

3、获取某列的值累计

 Dim i As Integer
        Dim temp As Double
        Try
            temp = 0
            For i = 0 To grd2.Rows.Count - 1
                If grd2.Rows(i).Cells("还款金额").Value <> 0 Then
                    temp += CDbl(grd2.Rows(i).Cells("还款金额").Value)
                End If
            Next
            txtdai.Text = CDbl(txtall.Text) - temp
        Catch ex As Exception


        End Try

4、获取列数量

  grd2.DisplayLayout.Bands(0).Columns.Count - 1

5、grd_InitializeLayout事件

  ''行选择
        'e.Layout.Override.SelectTypeRow = Infragistics.Win.UltraWinGrid.SelectType.Single
        ''进行行选择
        'e.Layout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect


        ''支持排序
        'e.Layout.ViewStyleBand = Infragistics.Win.UltraWinGrid.ViewStyleBand.Vertical
        'e.Layout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortMulti

‘禁止新增
        e.Layout.Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.No

’禁止删除
        e.Layout.Override.AllowDelete = Infragistics.Win.DefaultableBoolean.False

‘列宽度

  e.Layout.Bands(0).Columns(0).Width = 200

’全部列隐藏

 Dim i As Integer
        For i = 0 To e.Layout.Bands(0).Columns.Count - 1
           e.Layout.Bands(0).Columns(i).Hidden = True
       Next

6、统计,数据绑定后

   Try
            grd.DisplayLayout.Bands(0).SummaryFooterCaption = "合计:"
            grd.DisplayLayout.Override.SummaryFooterAppearance.TextHAlign = Infragistics.Win.HAlign.Right
            grd.DisplayLayout.Bands(0).Summaries.Add("C3", Infragistics.Win.UltraWinGrid.SummaryType.Sum, grd.DisplayLayout.Bands(0).Columns("借款金额"), Infragistics.Win.UltraWinGrid.SummaryPosition.UseSummaryPositionColumn)
            grd.DisplayLayout.Bands(0).Summaries("C3").DisplayFormat = "{0:C1}"
            grd.DisplayLayout.Bands(0).Summaries.Add("C4", Infragistics.Win.UltraWinGrid.SummaryType.Sum, grd.DisplayLayout.Bands(0).Columns("剩余金额"), Infragistics.Win.UltraWinGrid.SummaryPosition.UseSummaryPositionColumn)
            grd.DisplayLayout.Bands(0).Summaries("C4").DisplayFormat = "{0:C1}"
        Catch ex As Exception


        End Try


7、回车键到下一单元格



    Private Sub grd2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grd2.KeyDown
        Select Case e.KeyCode
            Case 13
                '回车键
                grd2.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.ExitEditMode, False, False)
                e.Handled = True
                grd2.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.NextCellInBand, False, False)
                grd2.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode, False, False)
        End Select


8、栅格化

  Private Sub shangehua()
        Try
            Dim i As Integer
            For i = 0 To grd.Rows.Count - 1
                '6-身份正类别
                '16-报名来源           
                grd.Rows(i).Cells("czjmc").Value = o.getccznrbyczbm(grd.Rows(i).Cells("czjmc").Value)
                grd.Rows(i).Cells("csfzlb").Value = o.getccznrbyczbm(grd.Rows(i).Cells("csfzlb").Value)
                grd.Rows(i).Cells("cbmly").Value = dept.getdeptname(grd.Rows(i).Cells("cbmly").Value)
                grd.Rows(i).Cells("cbklx").Value = o.getccznrbyczbm(grd.Rows(i).Cells("cbklx").Value)
                grd.Rows(i).Cells("cjzlx").Value = o.getccznrbyczbm(grd.Rows(i).Cells("cjzlx").Value)
                grd.Rows(i).Cells("czjcx").Value = o.getccznrbyczbm(grd.Rows(i).Cells("czjcx").Value)


                grd.Rows(i).Cells("ctjzj").Value = o.getccznrbyczbm2(grd.Rows(i).Cells("ctjzj").Value, "|")
                grd.Rows(i).Cells("izt").Value = tt.getzt(grd.Rows(i).Cells("izt").Value)
                grd.Rows(i).Cells("cjsr").Value = myuser.getusername((grd.Rows(i).Cells("cjsr").Value))
            Next
        Catch ex As Exception


        End Try


    End Sub


9、获取行数量

grd.Rows.Count.ToString


10、隐藏某列

  Try
            grd.DisplayLayout.Bands(0).Columns("公司").Hidden = True


        Catch ex As Exception


        End Try

11、使某行数据高亮红色显示

 Private Sub grd_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles grd.InitializeRow
        e.Row.CellAppearance.BackColor = Color.White
        If e.Row.Cells("公司").Text = 2 Then
            e.Row.CellAppearance.BackColor = Color.Red


        End If
    End Sub


12、    '冻结列
        Try
            '编码,号牌号码,挂车号牌,
            grd.DisplayLayout.UseFixedHeaders = True
            grd.DisplayLayout.Bands(0).Columns("编码").Header.Fixed = True
            grd.DisplayLayout.Bands(0).Columns("号牌号码").Header.Fixed = True
            grd.DisplayLayout.Bands(0).Columns("挂车号牌").Header.Fixed = True


        Catch ex As Exception


        End Try

你可能感兴趣的:(UltraWinGrid手记)