0

I would like to add a custom method for each row i.e. an open detail form that show details for the grid row the button has been clicked for.

Is there any easy solution for that?

EDIT:

What's wrong with my code to style the button?

Image img = imageList1.Images[5];
            repositoryItemButtonEdit1.Buttons.Clear();
            repositoryItemButtonEdit1.Buttons.Add(new EditorButton(ButtonPredefines.Left, "View Filter", 16, true, true, true, ImageLocation.Default, img));
            repositoryItemButtonEdit1.ButtonPressed += new ButtonPressedEventHandler(repositoryItemButtonEdit1_ButtonPressed);

ANSWER (use Glyph)

Image img = imageList1.Images[5];
repositoryItemButtonEdit1.Buttons.Clear();
repositoryItemButtonEdit1.Buttons.Add(
    new EditorButton(
        ButtonPredefines.Glyph, 
        "", 
        16, 
        true, 
        true, 
        true, 
        ImageLocation.Default, 
        img
    )
 );
 repositoryItemButtonEdit1.ButtonPressed += newButtonPressedEventHandler(repositoryItemButtonEdit1_ButtonPressed); 
Askolein
  • 3,250
  • 3
  • 28
  • 40
Mauro
  • 2,032
  • 3
  • 25
  • 47

2 Answers2

1

The easiest way to do that is to add a RepositoryItemButtonEdit as the ColumnEdit for the column.

Make sure you set the TextEdit property of the RepositoryItemButtonEdit to hidden, and configure the buttons property so that it has your image button.

Then handle the ButtonPressed Event of the repository item.

A simple event handler might look something like:

c#

private void RepositoryItemButtonEdit1_Click(object sender, System.EventArgs e)
{
    WhateverClass MyData = (WhateverClass)GridView1.GetFocusedRow();
    Form1 frmEdit = new Form1(MyData);
    frmEdit.Show();
}

vb.net

Private Sub RepositoryItemButtonEdit1_Click(sender As Object, e As System.EventArgs) Handles RepositoryItemButtonEdit1.Click
    Dim MyData As WhateverClass= CType(GridView1.GetFocusedRow(), WhateverClass)
    Dim frmEdit As New Form1(MyData)
    frmEdit.Show()
End Sub
Jay
  • 5,897
  • 1
  • 25
  • 28
1

just some addition to the answer above, because I faced a similar problem earlier.

  1. If you want to use an Image for the RepositoryItemButtonEdit button, don't forget to set the Button's Kind property to Glyph.
  2. If you want to display the editor button's Caption as well, you have to set the ImagePosition to other then MiddleCenter.
  3. I'd rather use the ButtonClick event, and check for the editor button's Index property.
  4. This link describes an interesting situation about this scenario.

Hope it will be also helpful.

Regards, Zoltán

Zoltán Tamási
  • 12,249
  • 8
  • 65
  • 93