Data column expression with variable - vb.net

I have following code and it is not working and calculate cost is zero. What is the mistake here?
.Columns.Add("Total", Type.GetType("System.Int32"))
.Columns("Total").Expression = "200 * " & FxRate.ToString
FxRate is a public variable.

when FxRate changes, the Total fields should automatically update.
The DataColumn.Expression does not provide a way to reference external variables. However, you can update the expression at any time.
You will need to call the update method when FxRate changes. If FxRate is a property, you can call the update method from its setter method.
Changes to the Expression will not be automatically be reflect on bound control. The update method will also need to tell the bindings to update. If you are binding through a BindingSource instance, call its ResetBindings(False) method. If you are binding directly to the DataTable, a more complex method would be to obtain theDataTable'sCurrencyManagerand call itsRefresh` method.
Assuming the DataTable variable is named dt, the following code will acquire the CurrencyManager; Me refers to the containing Form.
Dim mngr As CurrencyManager = CType(Me.BindingContext.Item(dt), CurrencyManager)
mngr.Refresh()
Edit: A working example using a BindingSource as requested in the comments.
In a new WinForm project, replace the contents of Form1.vb with the following code (all controls are created by this code - no designer support).
The code creates: a TextBox for changing the "Quantity" field", a Label to display the "Total" field, a NumericUpDown to allow changing the value of the FxRate property, and two button to allow navigating through the records in the DataTable.
The DataTable has three records. A record comprise two fields "Quantity" and "Total". "Total" will be computed as the product of the form's FxRate property and and the field "Quantity" by setting the Expression property of the "Quantity" column each time FxRate changes.
Public Class Form1
Inherits Form
Private tbInput As TextBox
Private lblTotal As Label
Private nudFxRate As NumericUpDown
Private btnNext As Button
Private btnPrevious As Button
Private bs As BindingSource
Private _FxRate As Int32
Private dt As DataTable
Public Sub New()
MyBase.New()
SetupControls()
dt = New DemoTable ' create a preconfigured DataTable
bs = New BindingSource(dt, Nothing)
SetBindings()
FxRate = 5
AttachControlEventHandlers()
End Sub
Public Property FxRate As Int32
Get
Return _FxRate
End Get
Set(value As Int32)
If value <> _FxRate Then
_FxRate = value
UpdateTotalExpression() ' only update the Expression if the value changes
End If
End Set
End Property
Private Sub UpdateTotalExpression()
' Change the expression to reflect the current value of FxRate
Dim totalColumn As DataColumn = dt.Columns("Total")
totalColumn.Expression = $"[Quantity] * {FxRate}"
' Expression changes do not notify the BindingSource of value changes
' so tell the BindingSource to reload all values
bs.ResetBindings(False)
End Sub
Private Sub tbInput_KeyPress(sender As Object, e As KeyPressEventArgs)
If e.KeyChar = Convert.ToChar(Keys.Enter) Then
Me.Validate() ' force tbInput to Validate
e.Handled = True ' eat the enter key
End If
End Sub
Private Sub tbInput_Validated(sender As Object, e As EventArgs)
' if tbInput successfully validated, push the values in the BindingSource to the DataTable
bs.EndEdit() ' push the editted value to the DataTable, causing Total to update
End Sub
Private Sub SetBindings()
' Update BindingSource once tbInput Validates successfully
tbInput.DataBindings.Add("Text", bs, "Quantity", True, DataSourceUpdateMode.OnValidation)
' lblTotal never updates the BindingSource
lblTotal.DataBindings.Add("Text", bs, "Total", True, DataSourceUpdateMode.Never)
' nudFxRate updates the FxRate property
nudFxRate.DataBindings.Add("Value", Me, "FxRate", True, DataSourceUpdateMode.OnPropertyChanged)
End Sub
Private Sub SetupControls()
tbInput = New System.Windows.Forms.TextBox()
lblTotal = New System.Windows.Forms.Label()
nudFxRate = New System.Windows.Forms.NumericUpDown()
btnNext = New System.Windows.Forms.Button()
btnPrevious = New System.Windows.Forms.Button()
CType(nudFxRate, System.ComponentModel.ISupportInitialize).BeginInit()
SuspendLayout()
'
'tbInput
'
tbInput.Location = New System.Drawing.Point(27, 40)
tbInput.Name = "tbInput"
tbInput.Size = New System.Drawing.Size(100, 22)
tbInput.TabIndex = 0
'
'lblTotal
'
lblTotal.AutoSize = False
lblTotal.BackColor = Color.Yellow
lblTotal.Location = New System.Drawing.Point(299, 42)
lblTotal.Name = "lblTotal"
lblTotal.Size = New System.Drawing.Size(100, 17)
lblTotal.TabIndex = 1
lblTotal.Text = "0"
'
'nudFxRate
'
nudFxRate.Location = New System.Drawing.Point(28, 94)
nudFxRate.Name = "nudFxRate"
nudFxRate.Size = New System.Drawing.Size(120, 22)
nudFxRate.TabIndex = 3
nudFxRate.Value = 5
'
'btnNext
'
btnNext.Location = New System.Drawing.Point(27, 136)
btnNext.Name = "btnNext"
btnNext.Size = New System.Drawing.Size(75, 23)
btnNext.TabIndex = 4
btnNext.Text = "Next"
btnNext.UseVisualStyleBackColor = True
'
'btnPrevious
'
btnPrevious.Location = New System.Drawing.Point(28, 171)
btnPrevious.Name = "btnPrevious"
btnPrevious.Size = New System.Drawing.Size(75, 23)
btnPrevious.TabIndex = 5
btnPrevious.Text = "Previous"
btnPrevious.UseVisualStyleBackColor = True
'
'Form1
'
AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
ClientSize = New System.Drawing.Size(800, 450)
Controls.Add(btnPrevious)
Controls.Add(btnNext)
Controls.Add(nudFxRate)
Controls.Add(lblTotal)
Controls.Add(tbInput)
Name = "Form1"
Text = "Form1"
CType(nudFxRate, System.ComponentModel.ISupportInitialize).EndInit()
ResumeLayout(False)
PerformLayout()
End Sub
Private Sub AttachControlEventHandlers()
AddHandler btnNext.Click, Sub() bs.MoveNext() ' move to next record in bindingsource
AddHandler btnPrevious.Click, Sub() bs.MovePrevious() ' move to previous record in bindingsource
AddHandler tbInput.KeyPress, AddressOf tbInput_KeyPress ' allow enter key to validate textbox
AddHandler tbInput.Validated, AddressOf tbInput_Validated ' update bindingsource on validation
End Sub
Private Class DemoTable : Inherits DataTable
Public Sub New()
Columns.Add("Quantity", GetType(Int32))
Columns.Add("Total", GetType(Int32))
Rows.Add(New Object() {10})
Rows.Add(New Object() {20})
Rows.Add(New Object() {30})
End Sub
End Class
End Class

Add the column FxRate. Change the expression of the Total column to "200 * FxRate", and the value of the Total column will be automatically set based on whatever FxRate is set to.
.Columns.Add("FxRate", Type.GetType("System.Int32"))
.Columns.Add("Total", Type.GetType("System.Int32"))
.Columns("Total").Expression = "200 * FxRate"
' Example of setting FxRate in row 0.
' (Assuming row 0 exists.)
.Rows(0).Item("FxRate") = 3

Related

Binding a Long/Int64 field to NumericUpdown leads to OleDbException "Too few parameters" on update

I am stuck with this problem the whole day, so maybe someone has a tip for me.
The environment: MS Access DB, VB.NET, OleDb-Driver, MS Access Database Engine 2016.
I am trying to bind a Long/Int64 field to a NumericUpDown control, but on update I get always the OleDbException "Too few parameters". I am pretty sure that the long field is the problem, because when I delete it from the table (and comment out the code for it) everything works fine. I am not sure that a NumericUpDown is suitable for this task, but it's underlying datatype is decimal and decimal has way more space as a long needs. So here is some code:
In the DataLayer:
Private Sub InitializeDataSet()
Dim LocFields = String.Join("], [", Fields)
Dim SQL As String = "SELECT [" & LocFields & "] FROM [" & Table & "]"
DAMain = New OleDbDataAdapter(SQL, Connection)
Using Builder As New OleDbCommandBuilder(DAMain) With {
.ConflictOption = ConflictOption.OverwriteChanges
}
Builder.GetInsertCommand()
Builder.GetUpdateCommand()
Builder.GetDeleteCommand()
End Using
DS = New DataSet
DAMain.Fill(DS, Table)
End Sub
Public Sub Update()
DAMain.Update(DS, Table) ' <-- Here the exception happens
End Sub
Public ReadOnly Property DataSource As Object
Get
Return DS
End Get
End Property
Public ReadOnly Property DataMember As String
Get
Return Table
End Get
End Property
We are here in a class, so the variables are:
Table = the name of the table
Fields = the list of the fields in the table
Connection = the OleDbConnection
DAMain = the OleDbDataAdapter
DS = the DataSet
In the Form:
Private DL As OleDbDataLayer
Private WithEvents BSource As New BindingSource
Public Sub New(DataLayer As OleDbDataLayer)
InitializeComponent()
DL = DataLayer
BSource.DataSource = DL.DataSource
BSource.DataMember = DL.DataMember
BSource.AllowNew = True
BSource.Sort = DL.OrderBy
BSource.Position = 0
InitializeFields()
End Sub
Private Sub DataUpdate()
BSource.EndEdit()
DL.Update()
End Sub
Private Sub InitializeFields()
NUD.Minimum = Long.MinValue
NUD.Maximum = Long.MaxValue
Dim Binding As New Binding("Value", BSource, "F_Long")
AddHandler Binding.Format, AddressOf FormatDBNull
AddHandler Binding.Parse, AddressOf ParseNumericUpDown
NUD.DataBindings.Add(Binding)
End Sub
Private Sub FormatDBNull(sender As Object, e As ConvertEventArgs)
If Convert.IsDBNull(e.Value) Then
Select Case e.DesiredType
Case = GetType(Decimal) : e.Value = 0
Case = GetType(Date) : e.Value = Today
Case = GetType(Boolean) : e.Value = False
Case Else
End Select
End If
End Sub
Private Sub ParseNumericUpDown(sender As Object, e As ConvertEventArgs)
Select Case e.DesiredType
Case = GetType(Byte)
e.Value = Convert.ToByte(e.Value)
Case = GetType(Short)
e.Value = Convert.ToInt16(e.Value)
Case = GetType(Integer)
e.Value = Convert.ToInt32(e.Value)
Case = GetType(Long)
e.Value = Convert.ToInt64(e.Value)
Case Else
' Do Nothing
End Select
End Sub
Here NUD is the NumericUpDown control which should be obvious.
Maybe I should use another control type? TextBox? MaskedTextBox?

vb.net Postgresql Database, using DataTable and display bitmap in Datagridview

I am using a Postgresql, and I would like to store a status value. These values should be of type integer (0 = OK, 1 = Not OK e.g.).
But I don't want to display these values as integer in my datagridview, I would like to display some small icons or bitmaps.
But how am I able to do this?
If I am using a DataColumn with Bitmap Type, I can't use the Integer type in my database.
This is how I fill my DataTable with the SQL data.
dtRecord is assigned to my DataGridview.
sda = New NpgsqlDataAdapter(pgCommand)
sda.Fill(dtRecord)
This was a test - but I can't insert the integer values from the SQL Database
Dim column1 As DataColumn = New DataColumn("Status")
column1.DataType = GetType(Bitmap)
Can someone give me any hints?
Thanks!
This is a fully working sample of how to load an image from the disk based on a value in the grid and display that image. In addition to the code below, you will need to drop a DataGridView on to the form from the Designer
Public Class Form1
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
InitialiseGridView()
InitialiseDataTable()
DataGridView1.DataSource = RecordsDataTable
End Sub
Dim RecordsDataTable As DataTable
Private Sub InitialiseGridView()
DataGridView1.AutoGenerateColumns = False
AddHandler DataGridView1.CellFormatting, AddressOf DataGridView1_CellFormatting
DataGridView1.Columns.Clear()
Dim dgvImageColumn As New DataGridViewImageColumn()
dgvImageColumn.Name = "dgvImageColumn"
dgvImageColumn.DataPropertyName = "dgvImageColumn"
dgvImageColumn.HeaderText = "Status"
DataGridView1.Columns.Add(dgvImageColumn)
Dim dgvTextColumn As New DataGridViewTextBoxColumn
dgvTextColumn.Name = "dgvTextColumn"
dgvTextColumn.DataPropertyName = "dgvTextColumn"
dgvTextColumn.HeaderText = "Other Text"
DataGridView1.Columns.Add(dgvTextColumn)
End Sub
Private Sub InitialiseDataTable()
RecordsDataTable = New DataTable()
RecordsDataTable.Columns.Add("dgvImageColumn", GetType(Integer))
RecordsDataTable.Columns.Add("dgvTextColumn", GetType(String))
RecordsDataTable.Rows.Add({1, "one"})
RecordsDataTable.Rows.Add({0, "two"})
RecordsDataTable.Rows.Add({1, "three"})
End Sub
Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs)
Dim thisDGV As DataGridView = DirectCast(sender, DataGridView)
If (thisDGV.Columns(e.ColumnIndex).Name = "dgvImageColumn") Then
Dim newImage As Image
If (e.Value.ToString() = "0") Then
newImage = Bitmap.FromFile("D:\Projects\Graphics\GreenDot.png")
Else
newImage = Bitmap.FromFile("D:\Projects\Graphics\RedDot.png")
End If
e.Value = newImage
e.FormattingApplied = True
End If
End Sub
End Class
This will give you a DataGridView that looks like:

How to create my own columns with DataGridView.AutoGenerateColumns = False

Using Windows Forms. Following example from DataGridView.AutoGenerateColumns Property. I'm trying to figure out how to add custom columns with AutoGenerateColumns = False.
Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SetBinding3()
End Sub
Private Class Employee
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Private _Name As String
End Class
Private employees As New List(Of Employee)
Dim bs As New BindingSource
Private Sub SetBinding3()
employees.Add(New Employee With {.Name = "Henry"})
employees.Add(New Employee With {.Name = "Mary"})
dgBilling.AutoGenerateColumns = False
bs.DataSource = employees
dgBilling.DataSource = bs
Dim col2 As New DataGridViewTextBoxColumn
col2.HeaderText = "Name"
col2.Name = "Name"
col2.ValueType = GetType(String)
col2.DataPropertyName = "Name"
col2.Width = 500
col2.DefaultCellStyle.ForeColor = Color.Black
col2.DefaultCellStyle.BackColor = Color.Beige
dgBilling.Columns.Add(col2)
dgBilling.Refresh()
End Sub
It all seems to work fine except I don't see the data in the DataGridView. If I click on it the names become selected and visible. But if I don't select then it's not visible. I tried setting the ForeColor and BackColor to no avail. How do I properly add a column with AutoGenerateColumns = False?
There's probably an easier way, but I've had success with this. Note that I have custom classes being bound to the DataGridView with List(Of T) and not a BindingSource. The string columns is a pairing of the object's property name and the column's header text. i.e. "Name" is Product.Name and "Product #" is what is shown in the DataGridView column header.
dgvItemList.AutoGenerateColumns = False
dgvItemList.DataSource = Services.MasterLists.Products.GetList
Dim columns As String() = {"ID", "ID",
"Name", "Product #",
"Description", "Description",
"Family", "Family",
"Comments", "Comments"}
Helpers.Controls.AddColumnsToDataGridView(dgvItemList, columns)
dgvItemList.Columns(0).Visible = False
dgvItemList.Columns(1).Width = 90
dgvItemList.Columns(2).Width = 200
dgvItemList.Columns(3).Width = 100
dgvItemList.Columns(4).Width = 200
And the definition of Helpers.Controls.AddColumnsToDataGridView:
Public Shared Sub AddColumnsToDataGridView(ByRef dgv As DataGridView, ByVal columns As String())
dgv.Columns.Clear()
For i As Integer = 0 To columns.Length - 1 Step 2
Dim column As DataGridViewColumn = New DataGridViewTextBoxColumn()
' i = index of the object's property name. i + 1 = the column name to show in the grid
column.DataPropertyName = columns(i)
column.Name = columns(i + 1)
dgv.Columns.Add(column)
Next
End Sub
The reason I do it this way is because I don't want the DataGridView to show all Properties of the Product object, just the fields I want shown.
Turns out I had an error in the RowPrePaint handler. It was referencing a column that didn't exist. As a result of the error the rows were not being rendered.
Private Sub dgv_RowPrePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles dgv.RowPrePaint
dgv.Rows(e.RowIndex).DefaultCellStyle.BackColor = dgv.Rows(e.RowIndex).Cells("RowColor").Value
End Sub
Once I fixed the error, everything showed fine!

Binding a custom property to a datatable field ,the source table is changing when navigating through items

I've got custom control inherited from a textbox I added a custom property as follows
Dim _MyVal As Object
Public Property MyVal As Object
Get
Return _MyVal
End Get
Set(value As Object)
_MyVal = value
If IsNothing(value) OrElse IsDBNull(value) Then
Me.Text = "Null"
Else
Select Case _MyVal
Case 1
Me.Text = "NewYork"
Case 2
Me.Text = "London"
Case 3
Me.Text = "Zwara"
Case Else
Me.Text = "Unknown"
End Select
End If
End Set
End Property
So I bound this property to a DataTable field in simple WinForm with a DataGridView and the custom textbox as follows
Public Class Form10
Dim dtMain As New DataTable
Dim bsMain As New BindingSource
Private Sub Form10_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
dtMain.Columns.Add("Name", GetType(String))
dtMain.Columns.Add("CityID", GetType(Integer))
dtMain.Rows.Add("John", 1)
dtMain.Rows.Add("Steve", 2)
dtMain.Rows.Add("Sara", 3)
dtMain.Rows.Add("Joe", DBNull.Value)
bsMain.DataSource = dtMain
dgv.DataSource = bsMain
txtCity.DataBindings.Add(New System.Windows.Forms.Binding("MyVal", bsMain, "CityID", False, DataSourceUpdateMode.OnPropertyChanged))
dtMain.AcceptChanges()
End Sub
My problems is, when I navigate through items, the DataTable is changed. Why does that happen?
While when I bind the field to a ComboBox SelectedValue property it works perfectly. It doesn't change the source through navigating; it changes when I change the SelectedValue property

CheckChanged event not firing with dynamic checkboxes?

I have a gridview control that is dynamically configured after a button-click event. Some of the columns contain dynamically added checkboxes. For some reason, I can't get the OnCheckedChanged event to fire for any of the checkboxes in this gridview.
Here's what fires after the button click event:
Private Sub BuildGridViewColumnList()
Try
' Clear all columns.
grdCommodityConfig.Columns.Clear()
' Add static columns.
Dim CommodityColumn As New BoundField
CommodityColumn.HeaderText = "Commodity"
CommodityColumn.DataField = "Commodity"
grdCommodityConfig.Columns.Add(CommodityColumn)
Dim PartTypeColumn As New BoundField
PartTypeColumn.HeaderText = "Part Type"
PartTypeColumn.DataField = "PartType"
grdCommodityConfig.Columns.Add(PartTypeColumn)
' Add dynamic columns
Dim ColumnHeaders As String = String.Empty
Database.GetCommodityConfig(txtAssyLine.Text, ColumnHeaders)
Dim ColumnList As List(Of String) = ColumnHeaders.Split(New Char() {","c}).ToList
' Add each column found in list returned from DB.
For Each ColumnName As String In ColumnList
Dim ItemTmpField As New TemplateField()
' create HeaderTemplate
ItemTmpField.HeaderTemplate = New DynamicallyTemplatedGridViewHandler(ListItemType.Header, ColumnName, "CheckBox")
' create ItemTemplate
ItemTmpField.ItemTemplate = New DynamicallyTemplatedGridViewHandler(ListItemType.Item, ColumnName, "CheckBox")
'create EditItemTemplate
ItemTmpField.EditItemTemplate = New DynamicallyTemplatedGridViewHandler(ListItemType.EditItem, ColumnName, "CheckBox")
' then add to the GridView
ItemTmpField.ItemStyle.HorizontalAlign = HorizontalAlign.Center
grdCommodityConfig.Columns.Add(ItemTmpField)
Next
Catch ex As Exception
Throw ex
End Try
End Sub
This is the class used to add the gridview & checkboxes:
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Collections.Specialized
Imports System.Data.SqlClient
Public Class DynamicallyTemplatedGridViewHandler
Implements ITemplate
Private ItemType As ListItemType
Private FieldName As String
Private InfoType As String
Public Sub New(item_type As ListItemType, field_name As String, info_type As String)
ItemType = item_type
FieldName = field_name
InfoType = info_type
End Sub
Public Sub InstantiateIn(Container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
Select Case ItemType
Case ListItemType.Header
Dim header_ltrl As New Literal()
header_ltrl.Text = "<b>" & FieldName & "</b>"
Container.Controls.Add(header_ltrl)
Exit Select
Case ListItemType.Item
Select Case InfoType
Case "CheckBox"
' for other 'non-command' i.e. the key and non key fields, bind textboxes with corresponding field values
Dim field_chkbox As New CheckBox()
field_chkbox.ID = FieldName
field_chkbox.Text = [String].Empty
' if Inert is intended no need to bind it with text..keep them empty
AddHandler field_chkbox.DataBinding, New EventHandler(AddressOf OnDataBinding)
AddHandler field_chkbox.CheckedChanged, New EventHandler(AddressOf OnCheckedChanged)
field_chkbox.CausesValidation = False
Container.Controls.Add(field_chkbox)
Case Else
Dim field_lbl As New Label()
field_lbl.ID = FieldName
field_lbl.Text = [String].Empty
'we will bind it later through 'OnDataBinding' event
AddHandler field_lbl.DataBinding, New EventHandler(AddressOf OnDataBinding)
Container.Controls.Add(field_lbl)
Exit Select
End Select
Exit Select
Case ListItemType.EditItem
If InfoType = "CheckBox" Then
' for other 'non-command' i.e. the key and non key fields, bind textboxes with corresponding field values
Dim field_chkbox As New CheckBox()
field_chkbox.ID = FieldName
field_chkbox.Text = [String].Empty
AddHandler field_chkbox.DataBinding, New EventHandler(AddressOf OnDataBinding)
AddHandler field_chkbox.CheckedChanged, New EventHandler(AddressOf OnCheckedChanged)
field_chkbox.CausesValidation = False
Container.Controls.Add(field_chkbox)
Else
' for other 'non-command' i.e. the key and non key fields, bind textboxes with corresponding field values
Dim field_txtbox As New TextBox()
field_txtbox.ID = FieldName
field_txtbox.Text = [String].Empty
AddHandler field_txtbox.DataBinding, New EventHandler(AddressOf OnDataBinding)
Container.Controls.Add(field_txtbox)
End If
Exit Select
End Select
End Sub
Private Sub OnDataBinding(sender As Object, e As EventArgs)
Dim bound_value_obj As Object = Nothing
Dim ctrl As Control = DirectCast(sender, Control)
Dim data_item_container As IDataItemContainer = DirectCast(ctrl.NamingContainer, IDataItemContainer)
bound_value_obj = DataBinder.Eval(data_item_container.DataItem, FieldName)
Select Case ItemType
Case ListItemType.Item
Dim field_ltrl As CheckBox = DirectCast(sender, CheckBox)
field_ltrl.Checked = CBool(bound_value_obj.ToString())
AddHandler field_ltrl.CheckedChanged, New EventHandler(AddressOf OnCheckedChanged)
field_ltrl.CausesValidation = False
Exit Select
Case ListItemType.EditItem
Dim field_txtbox As CheckBox = DirectCast(sender, CheckBox)
field_txtbox.Checked = CBool(bound_value_obj.ToString())
AddHandler field_txtbox.CheckedChanged, New EventHandler(AddressOf OnCheckedChanged)
field_txtbox.CausesValidation = False
Exit Select
End Select
End Sub
I believe I've found the answer to my own question. After some more Google searches, I added the following lines of code, and the CheckChanged event finally started firing. It's a step in the right direction!
Added this beneath the AddHandler statements in the DynamicallyTemplatedGridViewHandler class:
field_chkbox.AutoPostBack = True
As suggested by Tim S, I added the following in the page that houses the dynamic gridview control:
Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Me.IsPostBack Then
Try
' Need to build the column list dynamically.
BuildGridViewColumnList()
' Refresh GridView data.
BindGridViewData()
SetErrorMessage(String.Empty)
Catch ex As Exception
SetErrorMessage(ex.Message)
End Try
End If
End Sub