Home - Forums-.NET - FlyGrid.Net (Windows Forms) - flygrid_dialogbuttonclick

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

flygrid_dialogbuttonclick
Link Posted: 26-Oct-2006 09:56
Private Sub flyGrid_DialogButtonClick(ByVal sender As Object, ByVal port As FlyGridViewPort, ByVal col As Column, ByVal node As NodeBase)

    Dim newForm As New Form3
    newForm.TextBox1.Text = col.GetTextValue(node)
    newForm.btnOK.DialogResult = DialogResult.OK 'Sets default button
    newForm.ShowDialog(Me) 'Show newForm as a Dialog Box

    Dim strTest As String

    If newForm.DialogResult = DialogResult.OK Then 'Wait for dialog box to close
        strTest = newForm.TextBox1.Text
    End If

    col.SetValue(node, strTest)

End Sub


The above code is supposed to open up a form where I edit a textbox and then click ok. At that point the dialog column which was clicked is updated with the text from the textbox. This is working perfectly up to that point. But after this for some reason a new window will pop up for each row. So if I have 3 rows, I click to edit one and it works fine, then when im done another window will pop up and if I close that window one more will pop up. ALso I noticed if I edit the text in these other windows it will still update only the cell I originally clicked on. How do I stop these extra windows from popping up?
Link Posted: 26-Oct-2006 10:44
try following (more correct code):
Private Sub flyGrid_DialogButtonClick(ByVal sender As Object, ByVal port As FlyGridViewPort, ByVal col As Column, ByVal node As NodeBase)
    'create and setup form
    Dim newForm As New Form3
    newForm.TextBox1.Text = col.GetTextValue(node)
    newForm.btnOK.DialogResult = DialogResult.OK 'Sets default button
    'Show newForm as a Dialog Box and wait for dialog box to close
    If (newForm.ShowDialog(Me) = DialogResult.OK)  
      Dim strTest As String = newForm.TextBox1.Text
      col.SetValue(node, strTest)
    End If

End Sub
Link Posted: 26-Oct-2006 11:47
Still does the same thing. I think the problem might be with the way I am adding rows to the datagrid, here is the code for that:


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Me.FlyGrid1.Rows.DataSource = GetData(True)
        Me.FlyGrid1.Rows.RefreshNodes()
        AddHandler FlyGrid1.DialogButtonClick, AddressOf flyGrid_DialogButtonClick

    End Sub


When 'button1' is clicked it adds a row to the grid. Ok I actually just figured it out as I was typing this response. I moved the addhandler to the form_load sub and now it works properly. Maybe there were two problems, either way thanks for your help and quick reponse time.
Link Posted: 26-Oct-2006 13:11
Yes, there is a problem - each time you click a button - you add additional handler.
Please use following code to solve this problem:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

  Me.FlyGrid1.Rows.DataSource = GetData(True)
  Me.FlyGrid1.Rows.RefreshNodes()
  'before adding handler - remove handler to make sure that single handler is added.
  RemoveHandler FlyGrid1.DialogButtonClick, AddressOf flyGrid_DialogButtonClick
  AddHandler FlyGrid1.DialogButtonClick, AddressOf flyGrid_DialogButtonClick

End Sub