Hi,
I have a windows form that basically just retrieves some data from a SQL database. I have on column on the database I need to change before rendering the form on the datagrid. the problem is that I do not know how I could get the value before its added in the datagrid so I can change it.
Here is a sample of my code that defines the datagrid columns:
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.SqlDataAdapter1.Fill(Me.DsCustomers1)
'Step 1: Create a DataGridTableStyle & set mappingname to table.
Dim tableStyle As New DataGridTableStyle
tableStyle.MappingName = "Customers"
'Step 2: Create DataGridColumnStyle for each col
' we want to see in the grid and in the
' order that we want to see them.
' Use a PropertyDescriptor to create a formatted
' column. First get the PropertyDescriptorCollection
' for the data source and data member.
Dim pcol As PropertyDescriptorCollection = _
Me.BindingContext(DsCustomers1, "Customers"). _
GetItemProperties()
' Create a formatted column using a PropertyDescriptor.
' The formatting character "c" specifies a currency format. */
Dim column As _
New DataGridTextBoxColumn(pcol("TotalAmount"), "c", True)
'Dim column As New DataGridTextBoxColumn
column.MappingName = "TotalAmount"
column.HeaderText = "TotalAmount"
tableStyle.GridColumnStyles.Add(column)
column = New DataGridTextBoxColumn
column.MappingName = "InterVal" ' formatCol("Interval")
column.HeaderText = "International"
tableStyle.GridColumnStyles.Add(column)
column = New DataGridTextBoxColumn
column.MappingName = "ID"
column.HeaderText = "ID"
tableStyle.GridColumnStyles.Add(column)
Me.DataGrid1.TableStyles.Add(tableStyle)
End Sub
Look at the formatCol, this is the column I want to change the original value and I have a function I need to run over each value of the datagrid. Something like: column.MappingName = formatCol("Interval") but this obviously doesn't work. I believe I cannot do this here because the datagrid is not instantiated at this point and probably I can't do it this way. Look at the TotalAmount field, there I managed to format the column, but that's not exactly what I want to do, because its not just formatting the column for "Interval", its running a function over each record whcih will change the value.
Hope anyone can share some ideas on this and how I could get it right, appreciate it. I am back to work finally
I have a windows form that basically just retrieves some data from a SQL database. I have on column on the database I need to change before rendering the form on the datagrid. the problem is that I do not know how I could get the value before its added in the datagrid so I can change it.
Here is a sample of my code that defines the datagrid columns:
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.SqlDataAdapter1.Fill(Me.DsCustomers1)
'Step 1: Create a DataGridTableStyle & set mappingname to table.
Dim tableStyle As New DataGridTableStyle
tableStyle.MappingName = "Customers"
'Step 2: Create DataGridColumnStyle for each col
' we want to see in the grid and in the
' order that we want to see them.
' Use a PropertyDescriptor to create a formatted
' column. First get the PropertyDescriptorCollection
' for the data source and data member.
Dim pcol As PropertyDescriptorCollection = _
Me.BindingContext(DsCustomers1, "Customers"). _
GetItemProperties()
' Create a formatted column using a PropertyDescriptor.
' The formatting character "c" specifies a currency format. */
Dim column As _
New DataGridTextBoxColumn(pcol("TotalAmount"), "c", True)
'Dim column As New DataGridTextBoxColumn
column.MappingName = "TotalAmount"
column.HeaderText = "TotalAmount"
tableStyle.GridColumnStyles.Add(column)
column = New DataGridTextBoxColumn
column.MappingName = "InterVal" ' formatCol("Interval")
column.HeaderText = "International"
tableStyle.GridColumnStyles.Add(column)
column = New DataGridTextBoxColumn
column.MappingName = "ID"
column.HeaderText = "ID"
tableStyle.GridColumnStyles.Add(column)
Me.DataGrid1.TableStyles.Add(tableStyle)
End Sub
Look at the formatCol, this is the column I want to change the original value and I have a function I need to run over each value of the datagrid. Something like: column.MappingName = formatCol("Interval") but this obviously doesn't work. I believe I cannot do this here because the datagrid is not instantiated at this point and probably I can't do it this way. Look at the TotalAmount field, there I managed to format the column, but that's not exactly what I want to do, because its not just formatting the column for "Interval", its running a function over each record whcih will change the value.
Hope anyone can share some ideas on this and how I could get it right, appreciate it. I am back to work finally