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 / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

DataGridView.CurrentCell (Set)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michel Walsh - 14 Feb 2008 23:32 GMT
Someone has an example, C#,  about how to set the cell(int row, int col) as
the current cell for a DataGridView. The example, in the help file, about
DataGrid.CurrentCell Property (Set)

myGrid.CurrentCell = new DataGridCell(1,1);

does not work, fro a DataGridView, since we cannot create a DataGridView
Cell while specifying only its row and column.

Vanderghast, Access MVP
Michel Walsh - 14 Feb 2008 23:41 GMT
Sorry for the bandwidth, just found that I just have to point to that said
cell, after all... doh. No need to 'create' one, as the example from
DataGrid leads us to think. The following works:

   dataGridView1.CurrentCell = dataGridView1.Rows[iRow].Cells[iCol];

Vanderghast, Access MVP

> Someone has an example, C#,  about how to set the cell(int row, int col)
> as the current cell for a DataGridView. The example, in the help file,
[quoted text clipped - 6 lines]
>
> Vanderghast, Access MVP
Nicholas Paldino [.NET/C# MVP] - 15 Feb 2008 03:30 GMT
Michael,

   There are more succinct ways of doing this:

dataGridView1.CurrentCellAddress = new Point(1, 1);

   Or, if you wish:

dataGridView1.CurrentCell = dataGridView1[1, 1];

   Both should have the same effect, although the top example will help
prevent unsharing of rows, which is good when you are using the grid in
virtual mode.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Sorry for the bandwidth, just found that I just have to point to that said
> cell, after all... doh. No need to 'create' one, as the example from
[quoted text clipped - 14 lines]
>>
>> Vanderghast, Access MVP
Michel Walsh - 15 Feb 2008 14:15 GMT
If I can ask you one more question.

While

   dataGridView1.CurrentCell = dataGridView1[1, 1];

is fine for me, if I consider dataGridView[1,1] is a reference (a pointer)
to an existing cell, and then CurrentCell property just 'set the focus' on
that 'object reference' it got as its 'value', I fail to see how:

   dataGridView1.CurrentCellAddress = new Point(1, 1);

could even work, since

   new Point(1, 1)

is also a reference, but totally unrelated to any cell-references
(cell-pointers) owned by the dataGridView object. With this, in
consideration, can you explain the inner-working of

   dataGridView1.CurrentCellAddress = new Point(1, 1);

Thanks for your time
Vanderghast, Access MVP

> Michael,
>
[quoted text clipped - 9 lines]
> prevent unsharing of rows, which is good when you are using the grid in
> virtual mode.
Nicholas Paldino [.NET/C# MVP] - 16 Feb 2008 19:06 GMT
Michel,

   As you and Andrus pointed out, you the CurrentCellAddress property is
read-only, so you can't set it.

   So only the first example I gave is valid.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> If I can ask you one more question.
>
[quoted text clipped - 34 lines]
>> prevent unsharing of rows, which is good when you are using the grid in
>> virtual mode.
Andrus - 15 Feb 2008 17:58 GMT
> dataGridView1.CurrentCellAddress = new Point(1, 1);

causes error
'System.Windows.Forms.DataGridView.CurrentCellAddress' cannot be assigned
to -- it is read only

So how to use it ?

Andrus.

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.