issues with user control inside a DataRepeater

Locked issues with user control inside a DataRepeater

  • martedì 29 maggio 2012 15:51
     
     

    Hi,

    In WinForm, I have a user control which contains a textbox and a button (with an image on the button). In the user control, I have a property to change the width of the textbox. I put the user control on a DataRepeater. In Design time, it is good, I see the textbox, the button and his image. I can change the width property.

    But at run time, it is the horror. The user control lost the image of the button and width (it has the original width) and I can’t intercept the event on the button. Everything is good with the same user control when I put it on a form or a panel.

    In the same DataRepeater I put also TextBox. The DataRepeater bound with a Business List Base (Businee objects from CSLA). The binding is ok for the textbox inside the DataRepeater but not for the user control.

    Thanks if you have a solution.

    Dominique

Tutte le risposte

  • mercoledì 30 maggio 2012 08:39
    Moderatore
     
     

    Hi Dominique,

    I didn't reproduce this scenario. Would you like to upload your project here?

    I look forward you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • mercoledì 30 maggio 2012 16:53
     
     

    Thanks, Mike, for your answer

    I added my user control on a small sample project and I can upload it.

    But how can I upload a file (.zip) ?

  • giovedì 31 maggio 2012 03:57
    Moderatore
     
     

    Hi dg78,

    Upload your project on skydrive, and post the download link here.

    Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • giovedì 31 maggio 2012 07:03
     
     

    Hi Mike,

    I can’t upload the project (too big) but I do a small project to see the problem.

    I used the sample in this article :

    http://blogs.msdn.com/b/vsdata/archive/2009/08/12/datarepeater-control-for-windows-forms.aspx and I added my user control : ucTBL (textbox / Button / Label).

    I put a ucTBL in the DataRepeater.

    In the IDE it is OK but at runtime each property is lost : width, image, binding and I can’t intercept the mouse click  on the button.

    I put also a ucTBL outside the DataRepeater and it is OK .. but only for the selected item (it is normal).

    Here the binding is good, it is the good image and width.

    I put a breakpoint on Button1_Click in  the ucTBL. It is OK with the ucTBL outside the DataRepeater and Not OK with ucTBL inside the DataRepeater.

    I upload this sample at SkyDrive :

    https://skydrive.live.com/redir?resid=509DBC4A5D9AD957!129&authkey=!APkjWXR-8_FoTD4

    Thanks for help.

    Dominique

  • giovedì 31 maggio 2012 10:35
    Moderatore
     
      Contiene codice

    Hi Dg78,

    I have test your code, after I add this code, it works on my side:

        Private Sub DataRepeater1_ItemCloned(sender As Object, e As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs) Handles DataRepeater1.ItemCloned
            Dim butS As Button = Me.UcTBL72.Controls("dgButton1")
            Dim f1S As FieldInfo = GetType(Control).GetField("EventClick", BindingFlags.[Static] Or BindingFlags.NonPublic)
            Dim objS As Object = f1S.GetValue(butS)
            Dim piS As PropertyInfo = butS.[GetType]().GetProperty("Events", BindingFlags.NonPublic Or BindingFlags.Instance)
            Dim listS As EventHandlerList = DirectCast(piS.GetValue(butS, Nothing), EventHandlerList)
            'list.[RemoveHandler](obj, list(obj))
    
    
            Dim butT As Button = e.DataRepeaterItem.Controls.Find("dgButton1", True)(0)
            Dim f1T As FieldInfo = GetType(Control).GetField("EventClick", BindingFlags.[Static] Or BindingFlags.NonPublic)
            Dim objT As Object = f1T.GetValue(butT)
            Dim piT As PropertyInfo = butT.[GetType]().GetProperty("Events", BindingFlags.NonPublic Or BindingFlags.Instance)
            Dim listT As EventHandlerList = DirectCast(piT.GetValue(butT, Nothing), EventHandlerList)
            listT.[AddHandler](objT, listS(objS))
        End Sub

    You know, the datarepeater control always clone a repeater Item from the template, and the template is designed in the design time. When clone the template, the event handlers are not copied. So we need to add them again.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • giovedì 31 maggio 2012 22:15
     
     

    Thanks, Mike, you solve my problem about event.

    I think that Microsoft should have included the code you wrote inside the DataRepeater. If I put several ucTBL inside the datarepeater I need to duplicate you code for each ucTBL. What’s a pain !!

    How do you solve the problems about properties (longeur, image) and about the binding of ucTBL7 ?

    Are there good documentation and samples about these points ?

    Best regards

  • venerdì 1 giugno 2012 03:25
    Moderatore
     
     

    Hi Dg78,

    I am afraid so. And so far, I haven't found such documentation. 

    Please report this on Microsoft connect site: http://connect.microsoft.com/VisualStudio/ if you want to let Microsoft know.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • mercoledì 6 giugno 2012 12:11
    Moderatore
     
     

    Hi Dg78,

    Would you mind to close this thread?

    About your question "How do you solve the problems about properties (longeur, image) and about the binding of ucTBL7 ?

    I suggest you to ask it in a new thread since this thread is a little old  with more details information.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • venerdì 8 giugno 2012 13:19
     
     

    Hi Mike,

    I don’t wish to close this thread because, as you say, I don’t have an answer about the question :

    "How do you solve the problems about properties (longeur, image) and about the binding of ucTBL7 ?" 

    I think that it is not a good idea to close this thread and open a new with the same question and the same details. All details information are in this thread with a link for a sample.

    Everybody that try this sample can see the problem between the form in IDE and the form during runtime : the properties are lost and the binding on ucTBL7 doesn’t work.

    Outside the DataRepeater, I put a ucTBL7 (it is the same that it is in the datarepeater : longeur = 60, the image in the button is a mail and there is the databinding ). It is good in this ucTBL7 but it is not good in the ucTBL7 inside the datarepeater : longueur = 120 (it is the default property), image = a book (always default property, TypeBtn = 0) and the databinding does not work).

    The ucTBL7 outside the datarepeater give the Postal Code and City but only for the select item in the datarepeater. I want the same but inside each item of the datarepeater.

    Best regards

    Dominique

  • lunedì 11 giugno 2012 05:42
    Moderatore
     
     

    Hi Dg78,

    But what property is longeur and image? There is no such properties in your usercontrol.

    Would you like to point me what I am missing?

    Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • lunedì 11 giugno 2012 07:29
     
      Contiene codice

    Thanks Mike for answer,

    The user control ucTBL7 contains a textbox, a button and a label (not exactly a label but a textbox in readonly).

    Longueur is a property in the user control ucTBL7. It means the width of the first textbox (for input).

    (Sorry, I wrote Longeur in the posts but it is Longueur).

    Image is the image of the button. In Properties /  Resources of the project, there are two images : book and email.

    Look the form Form1 in the IDE, you can see a ucTBL7 inside the datarepeater and another ucTBL7 outside the datarepeater. The ucTBL7 outside is a copy of the ucTBL7 inside.

    Longueur and image are managed in the user control ucTBL code :

      <Category("z2 en plus pour dgTextBox1"), Description("longueur du dgTextBox1")> _
      Public Property Longueur() As Integer
        Get
          Return Me.dgTextBox1.Width
        End Get
        Set(ByVal value As Integer)
          If Me.dgTextBox1.Width <> value Then
            'If OutputDebug Then
            Console.WriteLine(Me.dgTextBox1.Width.ToString + " / " + value.ToString)
            'End If
            Me.dgTextBox1.Width = value
            Me.dgButton1.Location = New Point(Me.dgTextBox1.Location.X + value + 3, Me.dgButton1.Location.Y)
            Me.dgTextBox2.Location = New Point(Me.dgButton1.Location.X + 29, Me.dgTextBox2.Location.Y)
            If mAvecLabel = False Then
              Me.Width = Me.dgTextBox1.Location.X + value + 29 ' 2 + 26 + 1
              Me.dgTextBox2.Width = 0
            Else
              If Me.Width < Me.dgTextBox2.Location.X Then
                Me.Width = Me.dgTextBox2.Location.X + 101
              End If
              Me.dgTextBox2.Width = Me.Width - Me.dgTextBox2.Location.X - 1
            End If
          End If
        End Set
      End Property ' modif zones
     
      <Category("z3 en plus pour dgButton"), _
      DefaultValue(9), _
      Description("buttun type : 0=book  1=mail")> _
      Public Property TypeBtn() As Integer
        Get
          Return mTypeBtn
        End Get
        Set(ByVal value As Integer)
          mTypeBtn = value
          If value = 0 Then
            Me.dgButton1.Image = My.Resources.book
          End If
          If value = 1 Then
            Me.dgButton1.Image = My.Resources.email
          End If
        End Set
      End Property

    In the user control, I put (with IDE), the width of the Textbox at 120 and the BackgroundImage of the button with the book image of Resources.

    For the two objects ucTBL7 inside and outside, I put (with IDE) Longueur = 60 and TypeBtn = 1 (image = email).

    I put also the databinding :

    - Texte1 : EmployeesBindingSource - Postal Code

    - Texte2: EmployeesBindingSource - City

    Then these two objects have the same Longueur (= width of the textbox) and the same image in the button (= email).

    In the IDE, the two objects are correct with Longueur = 60 and image = email.

    Run the code and now the ucTBL7 outside the datarepeater is always correct (same Longeur as in IDE and email image) and the binding is correct.

    Look the ucTBL7 inside the datarepeater and you see that Longeur take the default property in the user control ucTBL7 (= 120) instead the value = 60  (the width of the textbox of the ucTBL7 is twice the width of the textbox of the ucTBL7 outside) and the image change to become book image (default backgoundimage of the button). You can see also that the databinding does not work.

    Best Regards

    Dominique

  • martedì 12 giugno 2012 03:16
    Moderatore
     
     

    Hi Dominique,

    I didn't reproduce this scenario, would you like to upload your test project again?

    Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • martedì 12 giugno 2012 07:25
     
     

    Hi Mike,

    The test project is still on Skydrive at :

    https://skydrive.live.com/redir?resid=509DBC4A5D9AD957!129&authkey=!APkjWXR-8_FoTD4

    Thanks for help

    Dominique

  • martedì 12 giugno 2012 07:55
     
     
    at the same link, I added a note in Word with screen copy.
  • mercoledì 4 luglio 2012 06:36
     
     

    Dear Customer,

     

    Your question falls into the paid support category which requires a more in-depth level of support. Please visit the below link to see the various paid support options that are available to better meet your needs.

    http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone  


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Regards,
    Eric Yang
    Microsoft Online Community Support

  • mercoledì 4 luglio 2012 07:55
     
     

    Dear MSFT,

    Is it a joke ?

    Near one month after my question, because Mike leaves the question and nobody can answer, you decree that it is a paid question. It is too easy.

    I think that my question is almost about a bug. Now customers must pay for bugs ??

    I would point you that I am a partner with a contract that said : you can use managed forum and Microsoft answers in the two days.

    Perhaps it is not a managed forum, so give me the link for the good forum or reconsider your position.

    Dominique