Home All Groups Group Topic Archive Search About

DataGrid custom class

Author
2 Aug 2006 4:59 AM
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

Author
2 Aug 2006 7:35 AM
Pieter
Author
2 Aug 2006 8:32 AM
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.)
Author
7 Aug 2006 10:00 AM
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.)
Author
7 Aug 2006 12:55 PM
Pieter
Why do I never get such a help from Microsoft? :-)
Author
7 Aug 2006 3:55 PM
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

Show quoteHide quote
"Pieter" <pietercou***@hotmail.com> schreef in bericht
news:up%2396CiuGHA.2448@TK2MSFTNGP06.phx.gbl...
> Why do I never get such a help from Microsoft? :-)
>
Author
8 Aug 2006 10:37 AM
Pieter
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23iRlHnjuGHA.2448@TK2MSFTNGP06.phx.gbl...
> 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 :-)
Author
9 Aug 2006 4:09 AM
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.)
Author
7 Aug 2006 6:19 PM
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

Show quoteHide quote
"Pieter" <pietercou***@hotmail.com> schreef in bericht
news:up%2396CiuGHA.2448@TK2MSFTNGP06.phx.gbl...
> Why do I never get such a help from Microsoft? :-)
>
Author
7 Aug 2006 3:54 PM
Peter
Show quote Hide quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:y$L0lhguGHA.2004@TK2MSFTNGXA01.phx.gbl...
> 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.
Author
7 Aug 2006 4:08 PM
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


Show quoteHide quote
"Peter" <pczurak@nospam.nospam> schreef in bericht
news:%23qkKPojuGHA.2036@TK2MSFTNGP05.phx.gbl...
>
> "Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
> news:y$L0lhguGHA.2004@TK2MSFTNGXA01.phx.gbl...
>> 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.
>
Author
11 Aug 2006 5:36 AM
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.)
Author
14 Aug 2006 2:53 AM
Peter
Show quote Hide quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:ZFXUdgQvGHA.2004@TK2MSFTNGXA01.phx.gbl...
> 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
Author
14 Aug 2006 9:35 AM
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.)
Author
14 Aug 2006 3:07 PM
Peter
Show quote Hide quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:nV29FU4vGHA.1992@TK2MSFTNGXA01.phx.gbl...
> 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.
Author
15 Aug 2006 8:50 AM
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.)
Author
17 Aug 2006 4:15 AM
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.)
Author
18 Aug 2006 4:21 AM
Peter
Show quote Hide quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:66ViXfEwGHA.3028@TK2MSFTNGXA01.phx.gbl...
> 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.
Author
18 Aug 2006 5:14 AM
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

Show quoteHide quote
"Peter" <pczurak@nospam.nospam> schreef in bericht
news:efeLq4nwGHA.2260@TK2MSFTNGP03.phx.gbl...
>
> "Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
> news:66ViXfEwGHA.3028@TK2MSFTNGXA01.phx.gbl...
>> 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.
>
Author
18 Aug 2006 7:54 PM
Peter
Show quote Hide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uk3pJUowGHA.4476@TK2MSFTNGP02.phx.gbl...
> 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
>
> "Peter" <pczurak@nospam.nospam> schreef in bericht
> news:efeLq4nwGHA.2260@TK2MSFTNGP03.phx.gbl...
>>
>> "Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
>> news:66ViXfEwGHA.3028@TK2MSFTNGXA01.phx.gbl...
>>> 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.
>>
>
>

I have found the problem, the problem was the DataGrid itself was set to
ReadOnly, the columns and ColumnStyles were set to ReadOnly = false, but I
guess that does not override the DataGrid readonly property, I though that
it did.

Thanks everyone for your help.
Author
15 Aug 2006 8:50 AM
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.)