Datagrid allow edit in column when it's new row

P

Peter Proost

Hi group I'm making my own datagrid control, so for I've got a lot of things
working, combobox columns, checkbox columns, blobfield columns. But now I
would like to be able the disable certain columns for editing I know I can
use readonly for the columnstyle but this will also disallow me to edit the
cell when I add a new row.
So I was thinking of using the overrides sub Edit in my class which inherits
from DataGridTextBoxColumn
and then check if the current rownumber is smaller then the total number of
rownumbers, if it is true, disable editing else enable it. Now I was just
wondering if this is the best way to do it.

Private intAantalRijen as Integer

Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows.Forms.CurrencyManager, ByVal _ rowNum As Integer, ByVal
bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal _
instantText As String, ByVal cellIsVisible As Boolean)
If TypeOf (Me.DataGridTableStyle.DataGrid.DataSource) Is DataTable
Then
intAantalRijen =
DirectCast(Me.DataGridTableStyle.DataGrid.DataSource, DataTable).Rows.Count
End If
If rowNum = intAantalRijen Then
MyBase.Edit(source, rowNum, bounds, [readOnly], instantText,
cellIsVisible)
End If
End Sub

Greetz Peter
 
K

Ken Tucker [MVP]

Hi,

Yes that is probably the best method.
http://64.78.52.104/FAQ/WinForms/FAQ_c44c.asp#q823q


Ken
----------------------
Hi group I'm making my own datagrid control, so for I've got a lot of things
working, combobox columns, checkbox columns, blobfield columns. But now I
would like to be able the disable certain columns for editing I know I can
use readonly for the columnstyle but this will also disallow me to edit the
cell when I add a new row.
So I was thinking of using the overrides sub Edit in my class which inherits
from DataGridTextBoxColumn
and then check if the current rownumber is smaller then the total number of
rownumbers, if it is true, disable editing else enable it. Now I was just
wondering if this is the best way to do it.

Private intAantalRijen as Integer

Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows.Forms.CurrencyManager, ByVal _ rowNum As Integer, ByVal
bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal _
instantText As String, ByVal cellIsVisible As Boolean)
If TypeOf (Me.DataGridTableStyle.DataGrid.DataSource) Is DataTable
Then
intAantalRijen =
DirectCast(Me.DataGridTableStyle.DataGrid.DataSource, DataTable).Rows.Count
End If
If rowNum = intAantalRijen Then
MyBase.Edit(source, rowNum, bounds, [readOnly], instantText,
cellIsVisible)
End If
End Sub

Greetz Peter
 
P

Peter Proost

Thanks Ken,

now I know that I'm not makeing it to difficult, because there might as well
have been an easier solution which I didn't know.

Greetz Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top