Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Unable to invoke protected method of DataGrid in Paint method

Unable to invoke protected method of DataGrid in Paint method

Scheduled Pinned Locked Moved C#
csharphelpdata-structures
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kais4U
    wrote on last edited by
    #1

    Hi, I found a code on net which allows multiline text in the datagrid cell. The sample code wasin VB.net, I just converted it to C#. Now the problem is the GetMethod is returning me null instead of an object. The code snippet is attached below MethodInfo mi = dg.GetType().GetMethod("get_DataGridRows", BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); Array dgRowArray = (Array) mi.Invoke(this.dg, null); the mi object is not getting created. It always says undefined. Am executing the above code in the overrided paint event of the datagrid. Can anyone help me out Any help is highly appreciated. Thanks in advance Regards, Kais

    M 1 Reply Last reply
    0
    • K Kais4U

      Hi, I found a code on net which allows multiline text in the datagrid cell. The sample code wasin VB.net, I just converted it to C#. Now the problem is the GetMethod is returning me null instead of an object. The code snippet is attached below MethodInfo mi = dg.GetType().GetMethod("get_DataGridRows", BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); Array dgRowArray = (Array) mi.Invoke(this.dg, null); the mi object is not getting created. It always says undefined. Am executing the above code in the overrided paint event of the datagrid. Can anyone help me out Any help is highly appreciated. Thanks in advance Regards, Kais

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello Kais, I also had problems with MethodInfo. So I changed my code too InvokeRequired, by using a delegate. private delegate void OnPaintDelegate(System.Windows.Forms.PaintEventArgs e); protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if(InvokeRequired) { OnPaintDelegate(new OnPaintDelegate(_OnPaint), new object [] { e } ); return; } //Your code } Hope that helps you. All the best, Martin

      K 1 Reply Last reply
      0
      • M Martin 0

        Hello Kais, I also had problems with MethodInfo. So I changed my code too InvokeRequired, by using a delegate. private delegate void OnPaintDelegate(System.Windows.Forms.PaintEventArgs e); protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if(InvokeRequired) { OnPaintDelegate(new OnPaintDelegate(_OnPaint), new object [] { e } ); return; } //Your code } Hope that helps you. All the best, Martin

        K Offline
        K Offline
        Kais4U
        wrote on last edited by
        #3

        Hi Martin, Where do we need to define "InvokeRequired" variable? Also i have override the paint method which has 7 parameters. Is that an issue? Please guide me if am wrong. I want to make this work. Regards, Kais

        M 1 Reply Last reply
        0
        • K Kais4U

          Hi Martin, Where do we need to define "InvokeRequired" variable? Also i have override the paint method which has 7 parameters. Is that an issue? Please guide me if am wrong. I want to make this work. Regards, Kais

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #4

          Hi Kais, InvokeRequired is a member of System.Windows.Forms.Control. You can have as much parameters as you whant, as long as your delagates has the same. private delegate void xxxDelegate(..., ..., ..., ...); Hope that helps you! All the best, Martin

          K 1 Reply Last reply
          0
          • M Martin 0

            Hi Kais, InvokeRequired is a member of System.Windows.Forms.Control. You can have as much parameters as you whant, as long as your delagates has the same. private delegate void xxxDelegate(..., ..., ..., ...); Hope that helps you! All the best, Martin

            K Offline
            K Offline
            Kais4U
            wrote on last edited by
            #5

            Hi Martin, Thanks for your prompt reply. I added the peice of your code in my customized datagrid class which inherits from DataGrid. Now it throws me the following errors The name '_OnPaint' does not exist in the class or namespace CustomControl.CustomGrid.CustomDataGrid' CustomControl.CustomGrid.CustomDataGrid.OnPaintDelegate' denotes a 'class' which is not valid in the given context This might be a stupid thing i am asking. The delegate needs to be wrapped with the method. Where do i need to assign the method for it? Thanks in advance Regards, Kais

            M 2 Replies Last reply
            0
            • K Kais4U

              Hi Martin, Thanks for your prompt reply. I added the peice of your code in my customized datagrid class which inherits from DataGrid. Now it throws me the following errors The name '_OnPaint' does not exist in the class or namespace CustomControl.CustomGrid.CustomDataGrid' CustomControl.CustomGrid.CustomDataGrid.OnPaintDelegate' denotes a 'class' which is not valid in the given context This might be a stupid thing i am asking. The delegate needs to be wrapped with the method. Where do i need to assign the method for it? Thanks in advance Regards, Kais

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #6

              Sorry, Was my mistake! private delegate void get_DataGridRowsDelegate(..., ..., ..., ...); protected override void get_DataGridRows(..., ..., ..., ...) { if(InvokeRequired) { get_DataGridRowsDelegate(new get_DataGridRowsDelegate(get_DataGridRows), new object [] { ..., ..., ..., ..., } ); return; } //Your code } The method has to be your get_DataGridRows Method you asked for. With all the parameters you had. If its not working, please post the code here! Martin -- modified at 8:08 Monday 3rd July, 2006

              1 Reply Last reply
              0
              • K Kais4U

                Hi Martin, Thanks for your prompt reply. I added the peice of your code in my customized datagrid class which inherits from DataGrid. Now it throws me the following errors The name '_OnPaint' does not exist in the class or namespace CustomControl.CustomGrid.CustomDataGrid' CustomControl.CustomGrid.CustomDataGrid.OnPaintDelegate' denotes a 'class' which is not valid in the given context This might be a stupid thing i am asking. The delegate needs to be wrapped with the method. Where do i need to assign the method for it? Thanks in advance Regards, Kais

                M Offline
                M Offline
                Martin 0
                wrote on last edited by
                #7

                Was a little confused before. I mixed my code to yours and forgot your actual question.

                K 1 Reply Last reply
                0
                • M Martin 0

                  Was a little confused before. I mixed my code to yours and forgot your actual question.

                  K Offline
                  K Offline
                  Kais4U
                  wrote on last edited by
                  #8

                  Martin, Thats ok. But get_DataGridRows method is not available for override. How will this work? Regards, Kais

                  M 2 Replies Last reply
                  0
                  • K Kais4U

                    Martin, Thats ok. But get_DataGridRows method is not available for override. How will this work? Regards, Kais

                    M Offline
                    M Offline
                    Martin 0
                    wrote on last edited by
                    #9

                    In your case, you can create Method like you had before. private void get_DataGridRows(...... ; just insert code in your Method. Martin Please give me feedback, if it works.

                    1 Reply Last reply
                    0
                    • K Kais4U

                      Martin, Thats ok. But get_DataGridRows method is not available for override. How will this work? Regards, Kais

                      M Offline
                      M Offline
                      Martin 0
                      wrote on last edited by
                      #10

                      Again, it was code from my project.

                      K 2 Replies Last reply
                      0
                      • M Martin 0

                        Again, it was code from my project.

                        K Offline
                        K Offline
                        Kais4U
                        wrote on last edited by
                        #11

                        Ok let me try out. I need to leave for the day now. Catch you tomorrow.. Thank you very much for your suggestion and time. :) Regards, Kais

                        1 Reply Last reply
                        0
                        • M Martin 0

                          Again, it was code from my project.

                          K Offline
                          K Offline
                          Kais4U
                          wrote on last edited by
                          #12

                          hi Martin, In meanwhile is it possible for you to send me the complete sample code. I would be very greatful for you if i can get the sample code. Thanks for all your help Regards Kais

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups