Home Forums WinForms controls Xceed Grid for WinForms Hyperlink column

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17355 |

    Is there a type of hyperlink CellViewerManager/CellEditorManager?  If so, would you show me how to create it?

    Imported from legacy forums. Posted by Morgan (had 6044 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Morgan,

    There is none; however, you could try to use the LinkLabel class as demonstrated in the MSDN documentation at the URL: http://msdn.microsoft.com/en-us/library/system.windows.forms.linklabel.aspx

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 784 views)

    User (Old forums)
    Member
    Post count: 23064

    Yes, I have used the LinkLabel class before but I am not sure how to add it to the Grid.

    Imported from legacy forums. Posted by Morgan (had 314 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Morgan,

    Find next an implementation of LinkLabel as CellViewerManager in the Xceed Grid for .NET:

    LinkLabel label = new LinkLabel();

                starterGrid.Columns[ “ProductName” ].CellViewerManager = new CellViewerManager( label, “Text” );

                starterGrid.Columns[ “ProductName” ].ReadOnly = true;

    starterGrid.DataRowTemplate.Cells[ “ProductName” ].Click += new EventHandler( StarterGrid_Click );

    void StarterGrid_Click( object sender, EventArgs e )

            {

                DataCell cell = sender as DataCell;

     

     

                if( cell.CellViewerManager.Control.GetType() == typeof( LinkLabel ) )

                {

                    LinkLabel label = cell.CellViewerManager.Control as LinkLabel;

                    // Specify that the link was visited.

                    label.LinkVisited = true;

                    // Navigate to a URL.

                    System.Diagnostics.Process.Start( http://www.xceed.com” );

                }

            }

    ..

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 542 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks, this does give the look of a hyperlink but not exactly the behavior.  The mouse cursor does not change to a hand.

    Thanks anyway.

    Imported from legacy forums. Posted by Morgan (had 614 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Morgan,

    The following should address your requirements:

    LinkLabel label = new LinkLabel();

                CellViewerManager cellViewerManager = new CellViewerManager( label, “Text” );

                starterGrid.Columns[ “ProductName” ].CellViewerManager = cellViewerManager;

                starterGrid.Columns[ “ProductName” ].ReadOnly = true;

                int count = starterGrid.DataRows.Count;

                for( int i = 0; i < count; ++i )

                {

                    starterGrid.DataRows[ i ].Cells[ “ProductName” ].MouseEnter += new EventHandler( StarterGrid_MouseEnter );

                    starterGrid.DataRows[ i ].Cells[ “ProductName” ].MouseLeave += new EventHandler( StarterGrid_MouseLeave );

                }

    void StarterGrid_MouseLeave( object sender, EventArgs e )

            {

                this.starterGrid.Cursor = Cursors.Arrow;

            }

     

            void StarterGrid_MouseEnter( object sender, EventArgs e )

            {

                this.starterGrid.Cursor = Cursors.Hand;

            }

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 465 views)

    User (Old forums)
    Member
    Post count: 23064

    Perfect, Thanks.

    Imported from legacy forums. Posted by Morgan (had 815 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

     

    I have a question related to this.

    In addition to click on a link, is it possible to edit it, i.e. can we have a link column that is not readonly?

     If so, how can I make the difference between clicking on a link vs starting to edit it? 

     

    Thanks,

    Marie 

    Imported from legacy forums. Posted by Marie4 (had 3325 views)

    Xceed Support
    Member
    Post count: 5658

    Hi,

    You could implement a CellEditorManager on that cell using a TextBox.  You must decide on which event you want to use to open the link on a browser or on editing the Cell: by default, the editor appears when you double click on the cells. Implementing CellEditors is shown in the online documentation of the Xceed grid for .NET.

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 391 views)

    User (Old forums)
    Member
    Post count: 23064

    Good! Thanks.

    Imported from legacy forums. Posted by Marie4 (had 557 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi!

    I have another quick question…

    I am in a class that inherits of Xceed.Grid.Viewers.CellViewerManager.

    How can I set the mouse cursor from there? I don’t think I can access my GridControl instance as it is done in the example… 

    This is where I am:

    public class MyCellViewerManager : Xceed.Grid.Viewers.CellViewerManager

    {

        public MyCellViewerManager() :

            base(new LinkLabel(), “Text”)

        {

            this.SettingControlValue += new global::Xceed.Grid.Viewers.CellViewerEventHandler(MyCellViewerManager_SettingControlValue);

        }

        void MyCellViewerManager_SettingControlValue(object sender, Xceed.Grid.Viewers.CellViewerEventArgs e)

        {

            // Just in case, remove handlers to avoid double calls

            e.Cell.MouseLeave -= new EventHandler(Cell_MouseLeave);

            e.Cell.MouseEnter -= new EventHandler(Cell_MouseEnter);

            e.Cell.Click -= new System.EventHandler(Cell_Click);

            e.Cell.Click += new System.EventHandler(Cell_Click);     

            e.Cell.MouseEnter += new EventHandler(Cell_MouseEnter);

            e.Cell.MouseLeave += new EventHandler(Cell_MouseLeave);

        }

            

        void Cell_MouseEnter(object sender, EventArgs e)

        {

            // Change cursor here

        }

        void Cell_MouseLeave(object sender, EventArgs e)

        {

            // Change cursor back

        }

        void Cell_Click(object sender, System.EventArgs e)

        {

            // Open link 🙂

        }

    }

     

    Thanks a lot!

    Marie 

    Imported from legacy forums. Posted by Marie4 (had 487 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Marie,

    You can get the gridControl instance via the property ParentGrid of the cell parameter of the overrided SetControlValueCore method.

    Explanation and examples on deriving the CellViewerManager are shown on the online documentation at:

    http://doc.xceedsoft.com/products/Xceedgrid/Deriving_from_the_CellViewerManager_class.html

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 370 views)

    User (Old forums)
    Member
    Post count: 23064

    Perfect!!! Thanks [:D]

    Imported from legacy forums. Posted by Marie4 (had 479 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi!

     When I do as mentionned above:

    LinkLabel label = cell.CellViewerManager.Control as LinkLabel;

    // Specify that the link was visited.
    label.LinkVisited = true; 

    All the cells from this column get purple, not just the one I visited. Is it possible to change the LinkLabel instance of single cells?

    Thanks,

    Marie

    Imported from legacy forums. Posted by Marie4 (had 451 views)

    Xceed Support
    Member
    Post count: 5658

    Hi,

    Since the CellViewManager’s LinkLabel control is recycled on the containers of your view, changing its LinkVisited property state will affect all the cells that use it.

    The solution for your scenario is to create another Boolean field in your data item that will contain the LinkVisited state. This field will, of course, be hidden on the view.

    Then, you will handle the SettingControlAppearance event on your CellViewerManager. This even is raised when the appearance of the underlining control is about to be set.

    You will have access to the Cell and Control parameters. Using the Cell you could have access to the underlying object via the SourceObject property. That Data Item’s VisitedLink field would be updated within a Click event handler.

    Then using the Control object, you could cast it into a LinkLabel and then set its LinkVisited property to the VisistedLink field’s value.

    The above should ensure that only the click that you have visited would be purple.  

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 1065 views)

Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.