I have a ultrawebgrid and when a user clicks on the row I want another ultrawebgrid to have the same seleted row. Something like this...
Dim selectedRow As UltraGridRow = wg1.DisplayLayout.SelectedRows(0)wg2.DisplayLayout.ActiveRow = selectedRow
First, you're mixing the concepts of "selected rows" and "active rows" between the two grid. An active row either has input focus or contains the cell that has input focus; the grid either has either exactly zero or one active rows at a time. By comparison, if you turn on row selection, you may have zero, one, or many selected rows at a time, any or none of which may be the active row.
Second, you can't set the active row in one WebGrid to be a row that exists in another WebGrid. Even if the two contain the same data, each row object is independent of each other. Instead, get some information from the appropriate row in one of your grids that allows you to uniquely identify it; a primary key is useful if your data has it. Then, find the corresponding row in the other grid that matches your unique identification, and select or activate that row as desired.
Ok, all that aside...
This is what I came up with. The only problem is that the ActiveRow doesnt get the SelectedRow properties (I understand the diff between Active and selected. I'm trying to emulate an end-user click where the row is made Active and it gets the selected row properties (ie back color, fore color). If I uncomment to the lines that set my formatting then that row stays like that all the time, not just when it's selected.
Thanks.
Dim count, i As Integer count = wgWirelessServices.Rows.Count Dim srvID As UltraGridColumn = wgWirelessServices.Columns(0) For i = 0 To count - 1 Step i + 1 If wgWirelessServices.Rows(i).GetCellText(srvID) = Session("service_id").ToString Then wgWirelessServices.DisplayLayout.ActiveRow = wgWirelessServices.Rows(i) ' wgWirelessServices.Rows(i).Style.BackColor = Drawing.Color.Orange ' wgWirelessServices.Rows(i).Style.ForeColor = Drawing.Color.White GridView1.SelectedIndex = i End If Next
How would I select multiple rows in the code behind? This only selects the last row that matches my criteria.
count = UltraWebGrid2.Rows.Count Dim srvID As UltraGridColumn = UltraWebGrid2.Columns(4) For i = 0 To count - 1 Step i + 1 If UltraWebGrid2.Rows(i).GetCellText(srvID).ToString() = CStr(myLocSrv) Then UltraWebGrid2.Rows(i).Selected = True End If Next
What you've described is expected. If you set the style properties of a row manually to "emulate" selection, then those style properties will remain all the time, even once the row is no longer active (or selected).
Why don't you just make the row selected, instead of (or possibly in addition to) making it active?
Your only other alternative is to monitor when a user activates a different row in the grid and clear the formatting you just applied.