deselect the current row

13 posts, 0 answers
  1. David
    David avatar
    8 posts
    Member since:
    Aug 2007

    Posted 27 May 2008 Link to this post

    Hello.  I am evaluating the Q1 2008 SP1 version of the RadGrid.

    After updating the datatsource of the grid, I have been trying to deselect the current row so that it is not highlighted.  I seem to have tried every suggestion on this forum, but to no avail.  Here is what I have tried (in VB):

    RadGridView1.CurrentRow.IsCurrent = False
    RadGridView1.CurrentRow = Nothing
    RadGridView1.MasterGridViewInfo.CurrentRow = Nothing
    RadGridView1.GridElement.Update(True)

    These don't work.  How can I deselect a row?

    Thanks,
    David
  2. Mike
    Mike avatar
    14 posts
    Member since:
    Mar 2008

    Posted 27 May 2008 Link to this post

    David,

    by chance have you tried clearing the selectedrows collection of the gridview?

    RadGridView1.SelectedRows.Clear()

  3. UI for WinForms is Visual Studio 2017 Ready
  4. David
    David avatar
    8 posts
    Member since:
    Aug 2007

    Posted 27 May 2008 Link to this post

    That does not work either.  The row is still highlighted.

    Thanks for the try, Mike!
  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 28 May 2008 Link to this post

    Hello David,

    Thank you for writing.

    I could not reproduce the behavior you've described. Maybe there is something specific to your scenario that is causing the issue. Please, could you provide me with a more detailed description and source-code fragments from your project?

    I am looking forward to your reply.

    Greetings,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. David
    David avatar
    8 posts
    Member since:
    Aug 2007

    Posted 28 May 2008 Link to this post

    Sure, but which line of code (from above) is supposed to do the trick?

    Here is my code.  It seems pretty straight forward to me:

    1 Sub refreshDataGridView()  
    2         Dim strSQL As String = "SELECT * FROM Inventory" 
    3         Dim da As Data.SqlClient.SqlDataAdapter = New Data.SqlClient.SqlDataAdapter(strSQL, connectionString)  
    4         Dim ds As Data.DataSet = New Data.DataSet  
    5         da.Fill(ds, "Inventory")  
    6         dt = ds.Tables("Inventory")  
    7         RadGridView1.DataSource = dt  
    8         RadGridView1.Columns("ItemID").IsVisible = False 
    9         RadGridView1.Columns("Category").IsVisible = False 
    10         RadGridView1.Columns("Supplier").IsVisible = False 
    11         RadGridView1.Columns("SupplierPartNum").IsVisible = False 
    12         RadGridView1.Columns("Manufacturer").IsVisible = False 
    13         RadGridView1.SelectedRows.Clear()  
    14 End Sub 

    Any thoughts?

    David

  7. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 30 May 2008 Link to this post

    Hello David,

    Thank you for sending your code.

    I have replaced this line:
    RadGridView1.SelectedRows.Clear(). 

    with the one below:
    Me.RadGridView1.CurrentRow.IsCurrent = False

    With the code changed as shown above, the row is properly deselected. Please use this approach, and let me know if you need any further assistance with this task.

    I am looking forward for your response.

    All the best,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. David
    David avatar
    8 posts
    Member since:
    Aug 2007

    Posted 30 May 2008 Link to this post

    I have tried that line of code before, but it does not always work (per my first posting).

    It seems to work when the routine is first called (on page load), but not any time after that.

    Any thoughts?

    David
  9. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 02 Jun 2008 Link to this post

    Hello David,

    Thank you for getting back to us.

    If you want to deselect the CurrentRow when the data source is changed, set its IsSelected property to false, as mentioned by Martin:
     
    Me.RadGridView1.CurrentRow.IsCurrent = False 

    If you want to hide the current row in general, you should change the grid theme. This can be done by processing the RowFormatting event. Consider the following code snippet:

    Private Sub radGridView1_RowFormatting(ByVal sender As ObjectByVal e As RowFormattingEventArgs) 
        If e.RowElement.IsCurrent Then 
            e.RowElement.DrawFill = False 
            e.RowElement.DrawBorder = False 
         End If 
    End Sub 

    I hope this helps. Do not hesitate to contact me if you have other questions.

    Regards,
    Jack
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. David
    David avatar
    8 posts
    Member since:
    Aug 2007

    Posted 02 Jun 2008 Link to this post

    I'm sorry, I might not have made it too clear.  I am just trying to de-select the row (remove the highlight)...not hide it.

    Me.RadGridView1.CurrentRow.IsCurrent = False
    Me.RadGridView1.CurrentRow.IsSelected = False

    These both do not work individually or in tandem after the the original load.

    Thanks,
    David
  11. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 03 Jun 2008 Link to this post

    Hello David,

    Thank you for getting back to me.

    I have tested different scenarios like described and I have discovered that there is an issue if you change existing DataSource of RadGridView.

    In this case the following code:

    Me.radGridView.CurrentRow.IsCurrent = False

    is working but does not change the visualization. We will address this in one of the upcoming releases.

    Currently, to avoid this undesired behavior please use the code below after changing the DataSource:

    Me.radGridView1.CurrentRow = Nothing 
    Me.radGridView1.GridElement.Update(Telerik.WinControls.UI.GridUINotifyAction.StateChanged) 

    If you have other questions, do not hesitate to contact me again.

    Greetings,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  12. raju
    raju avatar
    1 posts
    Member since:
    Aug 2010

    Posted 12 Aug 2010 Link to this post

    this information helped me a lot.
    i have used the following for unselecting therow of grid.

    gridview1.Currentrow.select=false;

    thanks
  13. ankusha
    ankusha avatar
    1 posts
    Member since:
    Aug 2012

    Posted 07 Mar Link to this post

    To deselect the row: 

    gridview1.SelectedIndex = -1

  14. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 08 Mar Link to this post

    Hello Ankusha,

    Thank you for writing.

    In order to clear the selected rows in RadGridView, you can iterate the SelectedRows collection and deselect each row:
    for (int i = 0; i < this.radGridView1.SelectedRows.Count; i++)
    {
        this.radGridView1.SelectedRows[i].IsSelected = false;
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready