Tampilkan postingan dengan label devexpress. Tampilkan semua postingan
Tampilkan postingan dengan label devexpress. Tampilkan semua postingan

Rabu, 22 Desember 2010

Nullifying blank cells

imports DevExpress.XtraGrid.Views.Grid
    Private Sub GridView1_ValidatingEditor(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs) Handles GridView1.ValidatingEditor
        Dim view As GridView = CType(sender, GridView)
        If view.FocusedColumn.FieldName = <numeric data field name> Then
            If Not e.Value Is Nothing AndAlso e.Value = "" Then
                e.Value = DBNull.Value
            End If
        End If
    End Sub

Me.RepositoryItemTextEdit1.Mask.EditMask = "\d*"
Me.RepositoryItemTextEdit1.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx
Me.RepositoryItemTextEdit1.Mask.UseMaskAsDisplayFormat = True

How to: Bind Individual Chart Series to Data (Runtime Sample)

Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...

Private Function CreateChartData(ByVal rowCount As Integer) As DataTable
    ' Create an empty table.
    Dim Table As New DataTable("Table1")

    ' Add two columns to the table.
    Table.Columns.Add("Argument", GetType(Int32))
    Table.Columns.Add("Value", GetType(Int32))

    ' Add data rows to the table.
    Dim Rnd As New Random()
    Dim Row As DataRow = Nothing
    Dim i As Integer
    For i = 0 To rowCount - 1
        Row = Table.NewRow()
        Row("Argument") = i
    Row("Value") = Rnd.Next(100)
    Table.Rows.Add(Row)
    Next i

    Return Table
End Function

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
    ' Create a chart.
    Dim Chart As New ChartControl()

    ' Create an empty Bar series and add it to the chart.
    Dim Series As New Series("Series1", ViewType.Bar)
    Chart.Series.Add(Series)

    ' Generate a data table and bind the series to it.
    Series.DataSource = CreateChartData(50)

    ' Specify data members to bind the series.
    Series.ArgumentScaleType = ScaleType.Numerical
    Series.ArgumentDataMember = "Argument"
    Series.ValueScaleType = ScaleType.Numerical
    Series.ValueDataMembers.AddRange(New String() {"Value"})

    ' Set some properties to get a nice-looking chart.
    CType(Series.View, SideBySideBarSeriesView).ColorEach = True
    CType(Chart.Diagram, XYDiagram).AxisY.Visible = False
    Chart.Legend.Visible = False

    ' Dock the chart into its parent and add it to the current form.
    Chart.Dock = DockStyle.Fill
    Me.Controls.Add(Chart)
End Sub

How to bind a chart to an MDB database at runtime

Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...

Namespace BindAChartAtRuntime
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            ' Create an empty chart.
            Dim chart As New ChartControl()

            ' Create data objects.
            Dim adapter As New OleDbDataAdapter("SELECT * FROM GSP",
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\gsp.mdb")
            Dim ds As New DataSet()
            'adapter.FillSchema(ds, SchemaType.Source);
            adapter.Fill(ds)

            ' Bind the chart to data.
            chart.DataSource = ds
            chart.DataAdapter = adapter

            ' Specify data members to bind the chart's series template.
            chart.SeriesDataMember = "Table.Year"
            chart.SeriesTemplate.ArgumentDataMember = "Table.Region"
            chart.SeriesTemplate.ValueDataMembers.AddRange(New String() { "Table.GSP" })

            ' Specify the template's series view.
            chart.SeriesTemplate.View = New StackedBarSeriesView()

            ' Adjust the X-axis and series labels' appearance.
            chart.SeriesTemplate.Label.Visible = False
            CType(chart.SeriesTemplate.View, StackedBarSeriesView).AxisX.Label.Angle = 25
            CType(chart.SeriesTemplate.View, StackedBarSeriesView).AxisX.Label.Antialiasing = True

            ' Dock the chart into its parent, and add it to the current form.
            chart.Dock = DockStyle.Fill
            Me.Controls.Add(chart)
        End Sub

    End Class
End Namespace

Obtaining and Setting Cell Values

Example 1

Dim CellValue As String
CellValue = GridView1.GetRowCellValue(2, "ID")



Example 2

The following sample code can be used to obtain the text displayed within the focused cell.


Dim nellValue As String = GridView.GetFocusedDisplayText()


Example 3

The following sample code can be used to get the value of the first column within the focused row.

Dim row As System.Data.DataRow = GridView1.GetDataRow(GridView1.FocusedRowHandle)
Dim CellValue As String = row(0)

Example 4

The following sample code can be used to change the focused cell's value.



With GridView1
   .SetRowCellValue(.FocusedRowHandle, .FocusedColumn, "New Value")
End With




Example 5

The following sample code can be used to set the value of the first column within the focused row.


System.Data.DataRow row = gridView1.GetDataRow(gridView1.FocusedRowHandle);
row[0] = "New Value";

Dim row As System.Data.DataRow = GridView1.GetDataRow(GridView1.FocusedRowHandle)
row(0) = "New Value"

Example - Implement Unbound Columns Via Event

Assume that the XtraGrid is bound to the [Order Details] table in the NWind database. The grid contains "Quantity", "UnitPrice" and "Discount" columns which are bound to the corresponding fields in the database table. The example below shows how to add an unbound column to the grid to display the amount of each order according to the expression: Quantity*UnitPrice*(1-Discount).
The result is displayed below:

For another example which illustrates working with unbound columns, see the Unbound Columns tutorial.
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Columns

Private Sub Form1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
   ' ...
   gridControl1.ForceInitialize()

   ' Create an unbound column.
   Dim unbColumn As GridColumn = GridView1.Columns.AddField("Total")
   unbColumn.VisibleIndex = GridView1.Columns.Count
   unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal
   ' Disable editing.
   unbColumn.OptionsColumn.AllowEdit = False
   ' Specify format settings.
   unbColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
   unbColumn.DisplayFormat.FormatString = "c"
   ' Customize the appearance settings.
   unbColumn.AppearanceCell.BackColor = Color.LemonChiffon
End Sub

' Returns the total amount for a specific row.
Private Function getTotalValue(ByVal view As ColumnView, _
  ByVal listSourceRowIndex As Integer) As Decimal
    Dim row As DataRow = NwindDataSet.Tables("Order Details").Rows(listSourceRowIndex)
    Dim unitPrice As Decimal = Convert.ToDecimal(row("UnitPrice"))
    Dim quantity As Decimal = Convert.ToDecimal(row("Quantity"))
    Dim discount As Decimal = Convert.ToDecimal(row("Discount"))
    Return unitPrice * quantity * (1 - discount)
End Function

' Provides data for the Total column.
Private Sub GridView1_CustomUnboundColumnData(ByVal sender As Object, _
  ByVal e As CustomColumnDataEventArgs) Handles GridView1.CustomUnboundColumnData
   If e.Column.FieldName = "Total" And e.IsGetData Then e.Value = _
     getTotalValue(CType(sender, ColumnView), e.ListSourceRowIndex)
End Sub
Example - Implement Unbound Columns Using Expressions

The following code shows how to create an unbound column (Ext Price) and populate it with data using expressions. Data for this column is calculated according to the formula: [Quantity] * [UnitPrice] * (1 - [Discount]), which is set via the GridColumn.UnboundExpression property. 

Imports DevExpress.XtraGrid.Columns

Dim columnExtPrice As GridColumn = New GridColumn()
columnExtPrice.FieldName = "ExtPrice"
columnExtPrice.Caption = "Ext Price"
columnExtPrice.UnboundType = DevExpress.Data.UnboundColumnType.Decimal
columnExtPrice.UnboundExpression = "[Quantity] * [UnitPrice] * (1 - [Discount])"
GridView1.Columns.Add(columnExtPrice)
columnExtPrice.VisibleIndex = 0