G
Guest
I seem to have gotten the data grid so that I can edit individual columns but
it has brought up some questions.
1) The only way that I can get a column to be editable is to make the whole
datagrid not read-only. Like:
Me.dgOrderItems.ReadOnly = False
The problem with that is that when I add a row to the datagrid I get two
rows, one that I added and one that just contains nulls (an empty row). I
override the default DataGridTextBoxColumn and set the ReadOnly property to
False but unless the ReadOnly property is set for the whole grid I cannot
edit the columns. I only use the overriden DataGridTextBoxColumn for certain
columns:
Dim dgEditableTextCol As New DataGridEditTextBoxColumn
dgEditableTextCol.HeaderText = "QTY"
dgEditableTextCol.MappingName = "qty"
dgEditableTextCol.Width = 35
dgEditableTextCol.ReadOnly = False
dgTblStyle.GridColumnStyles.Add(dgEditableTextCol)
dgEditableTextCol = New DataGridEditTextBoxColumn
dgEditableTextCol.HeaderText = "Unit Price"
dgEditableTextCol.MappingName = "UnitPrice"
dgEditableTextCol.Width = 70
dgEditableTextCol.Format = "C"
dgEditableTextCol.ReadOnly = False
dgTblStyle.GridColumnStyles.Add(dgEditableTextCol)
2) I have created a "calculated" column using the "Expression" property.
Me.columnextendedprice = New
System.Data.DataColumn("extendedprice", GetType(Decimal), Nothing,
System.Data.MappingType.Element)
Me.columnextendedprice.Expression = "qty * unitprice"
MyBase.Columns.Add(Me.columnextendedprice)
The problem is that this caclulated column is not getting updated after a
column/row has been edited. It is only when I leave the row altogether that
this expression seems to be evaluated. Is there a way to force an earlier
update.
3) Finally, I need to update other fields on the form when the data in the
DataGrid has been edited. I need some sort of notification when the column
has been edited so I can update the other fields in the form. For the columns
that I want to edit I currently have:
Protected Overloads Overrides Sub Edit(ByVal source As
CurrencyManager, ByVal rowNum As Integer, ByVal bounds As Rectangle, ByVal
[readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As
Boolean)
MyBase.Edit(source, rowNum, bounds, [readOnly], instantText,
cellIsVisible)
End Sub
Would this be a good place to fire/raise an event? When is this called? Is
it called after the text is changed (so instantText will contain the changed
value)?
Thank you for your help.
Kevin
it has brought up some questions.
1) The only way that I can get a column to be editable is to make the whole
datagrid not read-only. Like:
Me.dgOrderItems.ReadOnly = False
The problem with that is that when I add a row to the datagrid I get two
rows, one that I added and one that just contains nulls (an empty row). I
override the default DataGridTextBoxColumn and set the ReadOnly property to
False but unless the ReadOnly property is set for the whole grid I cannot
edit the columns. I only use the overriden DataGridTextBoxColumn for certain
columns:
Dim dgEditableTextCol As New DataGridEditTextBoxColumn
dgEditableTextCol.HeaderText = "QTY"
dgEditableTextCol.MappingName = "qty"
dgEditableTextCol.Width = 35
dgEditableTextCol.ReadOnly = False
dgTblStyle.GridColumnStyles.Add(dgEditableTextCol)
dgEditableTextCol = New DataGridEditTextBoxColumn
dgEditableTextCol.HeaderText = "Unit Price"
dgEditableTextCol.MappingName = "UnitPrice"
dgEditableTextCol.Width = 70
dgEditableTextCol.Format = "C"
dgEditableTextCol.ReadOnly = False
dgTblStyle.GridColumnStyles.Add(dgEditableTextCol)
2) I have created a "calculated" column using the "Expression" property.
Me.columnextendedprice = New
System.Data.DataColumn("extendedprice", GetType(Decimal), Nothing,
System.Data.MappingType.Element)
Me.columnextendedprice.Expression = "qty * unitprice"
MyBase.Columns.Add(Me.columnextendedprice)
The problem is that this caclulated column is not getting updated after a
column/row has been edited. It is only when I leave the row altogether that
this expression seems to be evaluated. Is there a way to force an earlier
update.
3) Finally, I need to update other fields on the form when the data in the
DataGrid has been edited. I need some sort of notification when the column
has been edited so I can update the other fields in the form. For the columns
that I want to edit I currently have:
Protected Overloads Overrides Sub Edit(ByVal source As
CurrencyManager, ByVal rowNum As Integer, ByVal bounds As Rectangle, ByVal
[readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As
Boolean)
MyBase.Edit(source, rowNum, bounds, [readOnly], instantText,
cellIsVisible)
End Sub
Would this be a good place to fire/raise an event? When is this called? Is
it called after the text is changed (so instantText will contain the changed
value)?
Thank you for your help.
Kevin