473,382 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How get focus in new row in DataGrid?

I have a WinForms DataGrid bound to a DataView. I insert a new row by
calling CurrencyManager.AddNew. However, the user cannot begin
entering data until he/she clicks in the first cell of the new row.
How can I set focus to the first cell of the new row in code so the
user can start typing?

Note that I have tried stting the DataGrid.CurrentCell property and
that does _not_ work.

Thanks.
--
Bill
Nov 16 '05 #1
7 7385
Bill,
I have a WinForms DataGrid bound to a DataView. I insert a new row by
calling CurrencyManager.AddNew. However, the user cannot begin
entering data until he/she clicks in the first cell of the new row.
How can I set focus to the first cell of the new row in code so the
user can start typing?

Note that I have tried stting the DataGrid.CurrentCell property and
that does _not_ work.


Try using the SelectedIndex member.

Regards,

Randy
Nov 16 '05 #2
Hi Bill,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to set focus to the first cell
of the newly added row in the DataGrid. If there is any misunderstanding,
please feel free to let me know.

Thanks for Randy's quick response. However, the SelectedIndex property is
only available in the web control. I think Bill is working on a WinForm
DataGrid. You might have ignored it.

As far as I know, when a new row is added to the collection, the current
row will be set to the newly added one. Now we can just call
dataGrid.Focus() method to set focus to the whole grid and the cursor will
be on the first cell of the blank row.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #3
On Fri, 04 Jun 2004 09:09:22 GMT, v-****@online.microsoft.com (Kevin
Yu [MSFT]) wrote:
As far as I know, when a new row is added to the collection, the current
row will be set to the newly added one. Now we can just call
dataGrid.Focus() method to set focus to the whole grid and the cursor will
be on the first cell of the blank row.


Thanks. I tried that. It does not work. Any other ideas? T
--
Bill
Nov 16 '05 #4
Hi Bill,

It works well on my computer, when the DataGrid got focus, it will set the
current cell to the first cell of the newly added row, if you
usedataGrid.Focus method right after AddNew. Is my understanding on your
question correct?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #5
My problem is that after calling AddNew the Focus both the DataGrid
and the CurrencyManager think that the current cell is the first
column in the new row. The CurrencyManager.Position property and the
DataGrid.CurrentCell.RowNumber and ColumnNumber properties all confirm
this.

The problem is that if I start typing the characters I type do not
appear in the new row (or anywhere else). Before I can type anything
into the new row through the UI I have to click the cel with the
mouse.

Are you able to enter data into the new row from the keyboard after
calling AddNew and Focus?

--
Bill
Nov 16 '05 #6
Hi Bill,

Yes, I was able to enter data into the new row from the keyboard after
calling AddNew and Focus. Please try to check if the AddNew and Focus
methods are called at the end of the function, so that no further operation
is done after these two calls, and we can ensure to put the focus in the
first cell of the newly added row.

If that still doesn't work, could you please send me a small package that
can reproduce the problem via email? I'd be happy to debug it. Removing
'online' from this no spam email is my real email address.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #7
Hi Bill,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: raj | last post by:
Hi, The focus in the datagrid is not lost even after leaving the datagrid. The selected cell is highlighted even when the focus from the datagrid is lost. This happens only after the .NET...
0
by: ED M. | last post by:
Hello all...I'm new to the board. I have a problem that I hope someone here might be able to solve for me. I am doing some clientside validation using Javascript. The text I am testing is...
5
by: Bryan Masephol | last post by:
Hi All I got a datagrid and a ComboBox on a form. I populate the combobox with years for all the data avaiable. When the user chooses a year the datagrid is populated with the specific years...
0
by: Shravan | last post by:
Hi, I have a Windows Forms Custom DataGrid, which is put in a usercontrol, which on setting DataSource is setting focus to grid. The call stack for setting the focus is as follows. This is not...
2
by: Bill C. | last post by:
Hi, I'm trying to implement a ComboBox drop-down column for a DataGrid. When a cell is selected in the ComboBox column I overlay a ComboBox over the cell and call: this.comboBox.Show();...
1
by: J.H.. | last post by:
With who way I can remove the focus from a DataGrid Control using the key Tab in a WinForm in C# ? The key Tab transports the focus in the next column of DataGrid and no in the next WinForm Control.
1
by: Jim Bayers | last post by:
This has been driving me crazy. server.transfer doesn't set the focus to the page I transfer to so when the user does a refresh, the results aren't what's expected. I have a datagrid on one...
2
by: kenglish_hi | last post by:
hello, I have a form with a datagrid and combo box. When the form loads up, i want the focus to be on the combo box. however, whenever it loads up, the focus is always on the datagrid. in the...
21
by: Sharon | last post by:
I have added an auto scroll feature to my DataGrid control like this: private void DoAutoScroll() { DataView dv = m_DataGrid.DataSource as DataView; DataGridCell cell = m_DataGrid.CurrentCell;...
0
by: =?Utf-8?B?R2FyeSBX?= | last post by:
Here is my problem. I have a datagrid that when you click on a row, it goes into edit mode and depending on where I clicked it the focus is on that control using Control.Focus(). I also have code...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.