This is a migrated thread and some comments may be shown as answers.

number of row

4 Answers 200 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gilberth
Top achievements
Rank 1
Gilberth asked on 22 Sep 2009, 09:40 PM
hello all, I have a question, is there any way to know which row number in which for example is modified or has a particular value, without that row number is altered when they are sorted or filtered the data in some way. My case is as follows, in my GridView displays data stored in a table and I add a checkbox column type, this makes the selection function of the row, it all works well, ie the selection function is to show later that these data from that row in another window and work properly when you select a row, but when you sort or filter the GridView shows me another number row, which leads to show how other data in the other window, stores the number of row because they already have the data to a local datatable and do not need another query to the database, giving me hope you understand and thanks in advance for any help you provide

4 Answers, 1 is accepted

Sort by
0
Gilberth
Top achievements
Rank 1
answered on 22 Sep 2009, 11:55 PM
I have an alteration in the programming of the checkbox, staying with the same function of a optionbutton, but doing a filter and with the checkbox checked the row disappears, apparently works the same way the checkbox, and remove the filter sample two rows with the checkbox enabled, only hope that a checkbox can be enabled across the gridview, ie only one can activate and deactivate the others are, I suppose that when you filter the actual data collection is not affected by the filter, just as when ordering by column, can you tell me how I can access that data collection for my programming work properly to place, with this also could solve the previous post, thanks in advance
0
Jack
Telerik team
answered on 24 Sep 2009, 06:24 AM
Hi Gilberth,

Regarding your questions:

1. You can use a hidden column that contains the row ID or you can use IndexOf method of the Rows collection to get the current row index. Here is a sample:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
    int rowIndex = this.radGridView1.Rows.IndexOf(e.CellElement.RowInfo); 
    //or 
    int rowIndex = e.CellElement.RowInfo["ID"].Value; 
    //... 

2. We found an issue related to the checkbox column when filtering is enabled. Please look at the following forum post for more details on how to work around it. I am not sure what do you mean by "accessing the data collection", however you can use the Rows collection to access all cell values. For example:

string value = this.radGridView1.Rows[3].Cells["Name"].Value.ToString(); 

I hope this helps. If you have more questions, don't hesitate to write back.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Gilberth
Top achievements
Rank 1
answered on 25 Sep 2009, 03:28 PM
Hello again, thanks for the help they have given me, I followed the option to create a column in which I place the index, that way I solved that problem, with respect to the second, I do not work, try to explain better ,

In a GridView displays information from a DataTable from the database, then I add 2 columns, one in which I keep the index of the rows and the second contains the ultilizando checkbox to select only one row, error or difficulty meeting is as follows, to just be a line which may be selected with the checkbox, by placing a filter, if the selected sets in the filter and select another row, to remove the filter are 2 rows selected me, my question is whether I can access all rows or entire collection but this leaked, the code that ultilizando so that only one row is selected is as follows:

Private Sub RadGVBuscar_ValueChanging(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.ValueChangingEventArgs) Handles RadGVBuscar.ValueChanging   
  
 If RadGVBuscar.CurrentCell IsNot Nothing Then   
  
  If RadGVBuscar.CurrentCell.ColumnIndex = 1 And Convert.ToBoolean(e.NewValue) = True Then   
  
   For i As Integer = 0 To RadGVBuscar.Rows.Count - 1   
  
    CType(RadGVBuscar.DataSource, DataTable).Rows(i).Item(1).Value = False   
  
   Next   
  
  End If   
  
 End If   
  
End Sub   

I hope I can help and thanks in advance for everything.
0
Jack
Telerik team
answered on 29 Sep 2009, 11:58 AM
Hello Gilberth,

Thank you for these details. It will be better to handle ValueChanged event in this case. Here is a sample:

Private Sub radGridView1_ValueChanged(ByVal sender As ObjectByVal e As EventArgs) 
    Dim checkBoxEditor As RadCheckBoxEditor = TryCast(sender, RadCheckBoxEditor) 
    If checkBoxEditor IsNot Nothing AndAlso CBool(checkBoxEditor.Value) = True AndAlso DirectCast(Me.radGridView1.CurrentColumn, GridViewDataColumn).UniqueName = "Bool" Then 
        Me.radGridView1.GridElement.BeginUpdate() 
        For i As Integer = 0 To Me.radGridView1.Rows.Count - 1 
            If Me.radGridView1.Rows(i) <> Me.radGridView1.CurrentRow Then 
                Me.radGridView1.Rows(i).Cells(3).Value = False 
            End If 
        Next 
        Me.radGridView1.GridElement.EndUpdate() 
        Me.radGridView1.CurrentCell.Value = True 
    End If 
End Sub 

However, the Rows collection of RadGridView will return the rows passed to the filtering. You should access directly your data source to access all rows, or you should handle FilterChanged event to synchronize the row state. 

I hope this helps. Should you have any questions, don't hesitate to ask. 

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Gilberth
Top achievements
Rank 1
Answers by
Gilberth
Top achievements
Rank 1
Jack
Telerik team
Share this question
or