DataGrid custom class

P

Peter

I have the following Class, but I would like to make one of the columns in
my DataGrid editable, how would I do that? When I use this class none of
the columns are editable even when I set the ReadOnly property to false?

Thanks


Peter


'-------------------------------------------------
Public Class MyDataGrid
Inherits DataGrid

Private _processVars As ProcessVariables
Private _sortDir As String = "NONE"
Private _sortVar As String = "NONE"

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)

Dim pt As New Point(e.X, e.Y)

Dim hit As DataGrid.HitTestInfo = Me.HitTest(pt)

If hit.Type = HitTestType.ColumnHeader AndAlso (hit.Column = 1 Or
hit.Column = 2) Then


Dim col As String =
Me.TableStyles(0).GridColumnStyles(hit.Column).MappingName

If Me._sortVar.Equals(col) Then
If hit.Column = 1 Then
If Me._sortDir.Equals("ASC") Then
Me._sortDir = "DESC"
ElseIf Me._sortDir = "DESC" Then
Me._sortDir = "NONE"
Else
Me._sortDir = "ASC"
End If
Else
If Me._sortDir.Equals("ASC") Then
Me._sortDir = "DESC"
Else
Me._sortDir = "ASC"
End If
End If
Else
Me._sortDir = "DESC"
Me._sortVar = col
End If

Me._processVars.SortGrid(Me, Me._sortDir, Me._sortVar)
Return 'don't call baseclass

End If

MyBase.OnMouseDown(e)

End Sub 'OnMouseDown

Public WriteOnly Property ProcessVars() As ProcessVariables
Set(ByVal Value As ProcessVariables)
Me._processVars = Value
End Set
End Property
End Class 'MyDataGrid
 
K

Kevin Yu [MSFT]

Pieter has give us a good sample to do the trick. You can make all other
columns non-editable to make one column editable.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
K

Kevin Yu [MSFT]

Hi Peter,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
P

Peter

Kevin Yu said:
Hi Peter,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

When I create a sample application it works, but in my application that I am
working on it does not work. The cursor goes into the grid cell like you
can edit the contents, but when I press a key nothing happens.
 
C

Cor Ligthert [MVP]

Pieter,

Because you probably don't use the webbased newsgroupreader and than does
not log on with your MSDN emailadres (account)

Otherwise there will be at least action taken on your question (checked if
there is already given a good answer (as Kevin did with yours and replied in
this case to check if the answer was as wanted), given an answer or bring
the answer back to their backoffice and reply accoording to that).

Cor
 
C

Cor Ligthert [MVP]

Peter,

Than in your case I would check the code of your application again. There
has never been any magic in code.

It works or it does not works, maybe you have used a wrong variable name or
not filled it with the right data. It is mostly hard to give any help in
that.

Cor
 
C

Cor Ligthert [MVP]

Pieter,

That does not mean that you cannot get an answer from Kevin, Jeffrey or
other Microsoft people if you don't do that, but than they do it completely
as community member, free to do that or not.

Cor
 
P

Pieter

Cor Ligthert said:
Because you probably don't use the webbased newsgroupreader and than does
not log on with your MSDN emailadres (account)

Ah, it HAS to be the web-based email-account? I'm using Outlook Express. I
tried it some time ago with the special-made MDSN-emaialdres, but I still
din't get answers :)
 
K

Kevin Yu [MSFT]

Yes, Pieter. Try to use web-based community and your registered MSDN email
address. And you'll be replied within 24 hours.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
K

Kevin Yu [MSFT]

Hi Peter,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
P

Peter

Kevin Yu said:
Hi Peter,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

I have not resolved my problem yet.

The problem is with my custom class the "MyDataGrid"
because when I use datagrid directly it works, but when I inherit the
DataGrid in MyDataGrid it does not work.

It's like my class is cosumming the KeyPress Event but it's never doing
anything with them.

here's the class again


'-------------------------------------------------
Public Class MyDataGrid
Inherits DataGrid

Private _processVars As ProcessVariables
Private _sortDir As String = "NONE"
Private _sortVar As String = "NONE"

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)

Dim pt As New Point(e.X, e.Y)

Dim hit As DataGrid.HitTestInfo = Me.HitTest(pt)

If hit.Type = HitTestType.ColumnHeader AndAlso (hit.Column = 1 Or
hit.Column = 2) Then


Dim col As String =
Me.TableStyles(0).GridColumnStyles(hit.Column).MappingName

If Me._sortVar.Equals(col) Then
If hit.Column = 1 Then
If Me._sortDir.Equals("ASC") Then
Me._sortDir = "DESC"
ElseIf Me._sortDir = "DESC" Then
Me._sortDir = "NONE"
Else
Me._sortDir = "ASC"
End If
Else
If Me._sortDir.Equals("ASC") Then
Me._sortDir = "DESC"
Else
Me._sortDir = "ASC"
End If
End If
Else
Me._sortDir = "DESC"
Me._sortVar = col
End If

Me._processVars.SortGrid(Me, Me._sortDir, Me._sortVar)
Return 'don't call baseclass

End If

MyBase.OnMouseDown(e)

End Sub 'OnMouseDown

Public WriteOnly Property ProcessVars() As ProcessVariables
Set(ByVal Value As ProcessVariables)
Me._processVars = Value
End Set
End Property
End Class 'MyDataGrid
 
K

Kevin Yu [MSFT]

Hi Peter,

I checked your code and found that currently, your control is allowing all
the columns to be editable, because at the end of OnMouseDown, you're
calling MyBase.OnMouseDown(e). So, if you only need the columns that meets
the criteria to be editable, you can put MyBase.OnMouseDown(e) inside the
if block.

Also, I don't quite understand why you use If hit.Type =
HitTestType.ColumnHeader AndAlso (hit.Column = 1 Or hit.Column = 2). Are
you allowing the second and third column to be editable? Or sortable?

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
P

Peter

Kevin Yu said:
Hi Peter,

I checked your code and found that currently, your control is allowing all
the columns to be editable, because at the end of OnMouseDown, you're
calling MyBase.OnMouseDown(e). So, if you only need the columns that meets
the criteria to be editable, you can put MyBase.OnMouseDown(e) inside the
if block.

Also, I don't quite understand why you use If hit.Type =
HitTestType.ColumnHeader AndAlso (hit.Column = 1 Or hit.Column = 2). Are
you allowing the second and third column to be editable? Or sortable?

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

I am allowing second and 3rd column to be sortable.

My problem is that I am not able to edit any of the columns, the cursor goes
into a cell like it would allow you to edit, but when I type nothing shows
up on the screen. If I don't use my custom class just grid directly
everything works, but if I use my class and inherit the DataGrid class it
does not work, so I know the problem is with my class, but I don't know how
or what to fix.
 
K

Kevin Yu [MSFT]

Hi Peter,

The MyDataGrid control works fine on my machine. When I press the key, a
certain cell can be edited. Have you ever handle the key events of the
Textbox in that cell?

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
K

Kevin Yu [MSFT]

I'm using exactly the code you have provided in your last post.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
K

Kevin Yu [MSFT]

Hi Peter,

Is there anything that I can help at this point?

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
P

Peter

Kevin Yu said:
Hi Peter,

The MyDataGrid control works fine on my machine. When I press the key, a
certain cell can be edited. Have you ever handle the key events of the
Textbox in that cell?

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

No I have not, how would I do that?

Currently I have no ideal how to trouble shoot this problem, I have no idea
where the key press or key down event go to.
 
C

Cor Ligthert [MVP]

Peter,

In my idea to debug this you should break your control down.

Start with a new one and add first the members that don't work in your idea
and debug them than, that mostly brings you to a solution. If you do that,
than you make it as well possible to send that small part to the newsgroups
so that Kevin or somebody else including me, can try your problem as well.

Cor
 

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