Home Forums WinForms controls Xceed Grid for WinForms Problems DirectCasting to Xceed.Grid.GridControl

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

    Hi all,

    I have a user control that contains buttons which will be used to navigate the current row in the GridControl

    Within the usercontrol, I have the string name of an Xceed Grid that I want to reference, then I loop through all the controls on the relevant form to find a match. Then I perform the following method:

    DirectCast(ctrl, Xceed.Grid.GridControl).MoveCurrentRow(Xceed.Grid.VerticalDirection.Top)

    where ctrl is the matching control. However rather than do this I would like to cast the relevant control (ctrl) to the GridControl only once and use that variable to perform the methods with.

    Problem is though I get a runtime error (Specified cast is not valid) on the following statement:

    Dim new_grid As Xceed.Grid.GridControl = DirectCast(ctrl, Xceed.Grid.GridControl)

    I know I have a workaround with using the first DirectCast statement each time I want to execute a method, but there seems to be a performance issue using this piece of code, so I would rather avoid it.

    Has anyone tried to perform such a casting to GridControl before?

    regards,

    Mac

    Imported from legacy forums. Posted by Dominic (had 3491 views)

    User (Old forums)
    Member
    Post count: 23064

    Instead of using a string reference in your usercontrol, wouldn’t it be better to just pass the instance of the GridControl? That way, you wouldn’t have to find a match, and you wouldn’t have to cast.

    Imported from legacy forums. Posted by Tommy (had 208 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Tommy,

    Rather than pass anything to the usercontrol, I have created a property that contains the string name of the relevant Xceed Grid. For this property, you actaully select the relevant name of the Xceed grid from a drop down list in the form designer.

    I found the code I was after to create this drop down list of relevant controls on a website and the end result is a list of string names rather than of the specific control type..

    So in my usercontrol, I just compare this property name against all the controls on the current form to find the match. Coding this way means everything is in the usercontrol. When it comes to creating an instance of the usercontrol I simply paste it into the form and set the property that indicates which Xceed Grid the instance of the usercontrol is relevant to.

    Come to think of it, I think I am better off just making the property of type Xceed Grid and getting the programmers to have to type it in, rather than select it from a drop down list.

    I would still like to know how to cast an instance of a Control to an Xceed Grid.

    Mac

    Imported from legacy forums. Posted by Dominic (had 323 views)

    User (Old forums)
    Member
    Post count: 23064

    I think, if you make the property of type Xceed.Grid.GridControl, the designer will automatically create a combobox for you with GridControls on the form. I haven’t tried it yet, but I think the designer is this flexible.

    Imported from legacy forums. Posted by Tommy (had 284 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Tommy,

    Yes, I tried that myself for the heck of it and made the public property in my usercontrol of type Xceed.Grid.GridControl. In the form designer i thought I would just have to type in the name of the relevant GridControl but was pleasantly suprised to see that it had automatically created a drop-down list with all the GridControls on the form!

    So I no longer need the directcast. Would mind knowing how to cast the GridControl though. I think I will ask Tech Support this one.

    Thanks for your help.

    regards,

    Mac

    Imported from legacy forums. Posted by Dominic (had 4558 views)

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