What I'd like to be able to do is select a grid row, click a button, and pass one of the selected row's cells to another method. Here's the stripped down code I have.
In the grid Initialize Layout event:
.CellClickActionDefault = UltraWebGrid.CellClickAction.RowSelect
.SelectTypeRowDefault = UltraWebGrid.SelectType.Single
.ActivationObject.BorderStyle = BorderStyle.Dotted
.BorderCollapseDefault = UltraWebGrid.BorderCollapse.Collapse
.RowSelectorsDefault = UltraWebGrid.RowSelectors.Yes
End With
In the button click event
sTest = uwgSearch1.DisplayLayout.ActiveCell.Value
I have done this before in other projects and didn't have any trouble. For some reason in this project everytime it posts back I get an object reference error. I'm stuck! Any ideas or suggestions would be appreciated.
Thanks
Jarrod,
There's a difference between an ActiveCell and a SelectedCell. It sounds like focus is being transferred from the grid to the button, when you click on the button to post back. This will remove the ActiveCell and ActiveRow from the grid, since they pertain exclusively to focus - which now belongs to the button. Perhaps if you explain a little more about your scenario and exactly what you're hoping to accomplish (why is the cell they clicked on important), we can offer an alternative solution.
-Tony
Thanks for the reply. The loss of focus makes sense. That may be it.
What I'm trying to setup is multiple grids that are used for drill-down. They will pick a row in the first grid, click a button, and then get further detail in the second grid. To do that, I need to pass the key value of the chosen row from the first grid to populate the second. I know that sounds like a good opportunity to use a hierarchical grid, but I don't think that will work in this case.
Possibly "Selected Cell" or "Selected Row" is an option. I haven't been able to find any information about it though. What would Selected Row's version of this
be?
Thanks - Jarrod.
You have a couple of options. You can use the SelectedRows collection (Grid.DisplayLayout.SelectedRows), or you can add an unbound column to your grid of type "Button" or use a templated column, and use the grid's events to figure out which row was clicked on. Using SelectedRows, you would go with the first item in the collection since you're only allowing single row selection.
My personal preference would be to set up a TemplateColumn and add a link button in there for "Details". You would use the grid's ItemCommand event, and set the linkButton's commandEvent and CommandArgs properties accordingly. I'd set the CommandArgs to the datakey of the row. Take a look at this post on using the ItemCommand and TemplateColumns.
The reason I particularly like this solution is because it takes the user from 2+ clicks, to a single click, which makes a happy user..