Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

How to set the black arrow at the right row in a DataGridView?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
david.vincent@ufo.org - 11 Jun 2007 14:50 GMT
During the initialization, I set the current selected row to the first row
of my DataGridView.
But the black arrow of the first column (what is the aim of this arrow?) is
set at a random row, not the same row that my selected one.
How to force the same row at the initialization time? (after the first
manual selection, it's ok)

Thanks for your help,
Jean-Michel
Morten Wennevik [C# MVP] - 11 Jun 2007 17:49 GMT
Hi Jean-Michel,

You are probably setting a certain row as selected, but the black triangle cursor follows the CurrentRow property.  The CurrentRow property is a read only property that follows CurrentCell, which you can set.

Try setting the CurrentCell property to a cell in the desired row.

dataGridView1.CurrentCell = dataGridView1.Rows[2].Cells[0];

> During the initialization, I set the current selected row to the first row
> of my DataGridView.
[quoted text clipped - 5 lines]
> Thanks for your help,
> Jean-Michel

Signature

Happy coding!
Morten Wennevik [C# MVP]

david.vincent@ufo.org - 11 Jun 2007 21:21 GMT
Thanks Wenning.
I always get an error "Current cell cannot be set to an invisible cell.",
both with CurrentCell and FirstDisplayedCell, even with grids with no
invisible column.
Is there a test to perform before?
Morten Wennevik [C# MVP] - 12 Jun 2007 15:47 GMT
> Thanks Wenning.
> I always get an error "Current cell cannot be set to an invisible cell.",
> both with CurrentCell and FirstDisplayedCell, even with grids with no
> invisible column.
> Is there a test to perform before?

Well I don't know what your grid looks like, but you can test for visibility before assigning the CurrentCell

            DataGridViewCell cell = dataGridView1.Rows[2].Cells[0];
            if(cell.Visible)
                dataGridView1.CurrentCell = dataGridView1.Rows[2].Cells[0];

You may also need to ensure the data is fed to the grid before trying to assign the CurrentCell.  In my sample I filled the DataGridView in the form constructor and set the CurrentCell property in the Form.Load event, however my code worked fine if I set the CurrentCell in the constructor as well.

Signature

Happy coding!
Morten Wennevik [C# MVP]


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.