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

GridView in user control, unselected row

7 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sason
Top achievements
Rank 1
Sason asked on 02 Aug 2010, 08:42 AM

Hi

i build a user control that include a GridView and more objects.
i need to display the grid to the user without selecting the first row.
in the DataBindingComplete Event i add this line to unselect row :

this.CurrentRow = null;


when the grid show in the first time it's ok, none of the rows selected.
but when i change the DataSource of the grid, the first row selected !

when i use the debuger i saw that after the DataBindingComplete event run the

SelectionChanged event run too.

 

when i use the debugger in the first time that the form show, I saw that DataBindingComplete event run and after that the SelectionChanged run and after that DataBindingComplete event run again.

And because of that the line that I add (this.CurrentRow = null;) run in the end and none of the row selected.

What can I do to unselect row ?

I whant that the code I write will be in the user control and not in the forms code.


7 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 02 Aug 2010, 10:52 AM
Hello Dror,

You could just call the ClearSelection() and CurrentRow = null after changing the data source, the DataBindingComplete event fires only once from what I've seen in my tests.

And if you are already using a custom control, create a property inside your control named DataSource that will handle the selection clearing after binding.

Best regards,
Emanuel Varga
0
Sason
Top achievements
Rank 1
answered on 02 Aug 2010, 12:07 PM
Hi,

are there is event that fire after DataBindingComplete ?
or the last one that fire on gridview ?
0
Emanuel Varga
Top achievements
Rank 1
answered on 02 Aug 2010, 01:10 PM
Hello Dror,

There is no other data binding related event after data binding complete, but why are you hesitating to call ClearSelection() and CurrentRow = null after setting a new data source?
0
Sason
Top achievements
Rank 1
answered on 02 Aug 2010, 01:12 PM
to minimize the code in the forms.
0
Emanuel Varga
Top achievements
Rank 1
answered on 02 Aug 2010, 01:17 PM
Not in the form, In the control create a property named DataSource something like:

public object DataSource
        {
            get
            {
                return radGridView1.DataSource;
            }
            set
            {
                radGridView1.DataSource = value;
                radGridView1.ClearSelection();
                radGridView1.CurrentRow = null;
            }
        }

or if you need a data source for more than this create a custom data source property just for the grid.

P.s. I'm assuming you've inherited from RadControl

Let me know if there is anything else i can do to help
0
Sason
Top achievements
Rank 1
answered on 02 Aug 2010, 01:55 PM
Thank you, iwill try and let you know.
0
Martin Vasilev
Telerik team
answered on 04 Aug 2010, 06:37 PM
Hi Dror,

Actually there is not a suitable event, which could be used to clear the selection and the current row after the data source has changed. However, your requirement sounds reasonable and we will consider to include a convenient way to do that in the future releases. For the time being you can use the tips, which Emanuel gives you. 

I have updated your Telerik points for bringing our attention on this. Let me know if you have any additional questions.

All the best,
Martin Vasilev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Sason
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Sason
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or