PC Review


Reply
Thread Tools Rate Thread

datagridview - set focus

 
 
Berryl Hesh
Guest
Posts: n/a
 
      2nd Dec 2008
When the dgv control is first initialized I want the focust to be in the 3rd
column of the first row with data. Code below caused the program to
terminate.

Thanks for sharing - BH

public void SetFocusToDataEntry() {
_dgv.Focus();
_dgv.CurrentCell = _dgv.Rows[1].Cells[2];
}


 
Reply With Quote
 
 
 
 
Beth
Guest
Posts: n/a
 
      2nd Dec 2008
Hi, Berryl.

Try commenting out your focus call.
My VB code works without it:
dgvReadOnly.CurrentCell = dgvReadOnly(gridColsToHide, row)

otherwise, it could be a syntax thing. Can't help you with the C# syntax,
sorry.

HTH

-Beth

"Berryl Hesh" wrote:

> When the dgv control is first initialized I want the focust to be in the 3rd
> column of the first row with data. Code below caused the program to
> terminate.
>
> Thanks for sharing - BH
>
> public void SetFocusToDataEntry() {
> _dgv.Focus();
> _dgv.CurrentCell = _dgv.Rows[1].Cells[2];
> }
>
>
>

 
Reply With Quote
 
Berryl Hesh
Guest
Posts: n/a
 
      14th Dec 2008
Hi Beth

It turns out I was my test case for this hadn't created a handle for the
control (ie, dgv.CreateControl, which a 'real' form does automatically for
you). That fixed this particular problem.

I probably wouldn't be much help with your VB syntax either :-). Thanks for
your reply.

Berryl

"Beth" <(E-Mail Removed)> wrote in message
news:25CA90AD-1925-4404-855E-(E-Mail Removed)...
> Hi, Berryl.
>
> Try commenting out your focus call.
> My VB code works without it:
> dgvReadOnly.CurrentCell = dgvReadOnly(gridColsToHide, row)
>
> otherwise, it could be a syntax thing. Can't help you with the C# syntax,
> sorry.
>
> HTH
>
> -Beth
>
> "Berryl Hesh" wrote:
>
>> When the dgv control is first initialized I want the focust to be in the
>> 3rd
>> column of the first row with data. Code below caused the program to
>> terminate.
>>
>> Thanks for sharing - BH
>>
>> public void SetFocusToDataEntry() {
>> _dgv.Focus();
>> _dgv.CurrentCell = _dgv.Rows[1].Cells[2];
>> }
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Focus CellEnter Event, DataGridView SePp Microsoft C# .NET 0 22nd Jan 2008 01:33 PM
Preventing focus from leaving DataGridView Larry Microsoft Dot NET Framework Forms 4 27th Dec 2007 06:26 PM
How to set focus back in DataGridView Cell Hank Microsoft Dot NET Framework Forms 2 8th Mar 2007 12:49 AM
Datagridview - Move Focus to a Particular Cell Paul Remblance Microsoft VB .NET 2 26th Jul 2006 12:00 PM
Deleting the last row of a DataGridView - focus? Michael Wong Microsoft Dot NET Framework Forms 0 4th Jan 2006 05:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:49 AM.