Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid focus or lack of focus?

Status
Not open for further replies.

KreativeKai

Programmer
Nov 12, 2004
33
0
0
US
I have an application that has a treeview setup. Depending on the node selected on the treeview a datagrid is loaded with appropriate data from SQL.

At this point the treeview shows with the node highlighted and the datagrid is displayed with the data.

I want to have the cursor positioned in row 0 column 1. I tried the following logic:

DataGrid.CurrentCell = New DataGridCell(1, 0)
DataGrid.Focus()

I'm having no success finding the correct syntax.

Any suggestions?

Lost in the Vast Sea of .NET

Visit my website at www.komputing.com
 
This is bull, but the only way i could get the focus
to change from a treeview afterselect was to use
sendkeys In my form the tabindex of the data grid followed the treeview control.
I really hope someone has better than this.

Code:
BindTableToDataGrid()
SendKeys.Send("{TAB}")
SendKeys.Send("{TAB}")



if it is to be it's up to me
 
Here is the code I've used which works.

DataGrid.CurrentCell = New DataGridCell(0, 0)
SendKeys.Send("{TAB}")
SendKeys.Send("{TAB}")
SendKeys.Send("{TAB}")
SendKeys.Send("{HOME}")

Like you said, this just doesn't seem like the best way to get focus on a datagrid.

Does anyone have a better suggestion?

Lost in the Vast Sea of .NET

Visit my website at www.komputing.com
 
This seems to focus the correct cell with a DataGridView control (you'll have to check if the same goes for the Datarid control as I don't have access to that at the minute):
Code:
DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(1)


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
OK, I believe the syntax that you used in the first place should work for just selecting a cell but this is just from memory (e.g. DataGrid1.CurrentCell = New DataGridCell(0, 1) )
I want to have the cursor positioned in row 0 column 1
Or maybe I'm getting confused by what you mean here. Do you mean that you just want the cell to be selected, or do you want the cursor to actually be in the cell as if the user was to start editing it?




____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I want the cursor to actually be in the cell as if the user was to start editing it.

DataGrid1.CurrentCell = New DataGridCell(0, 1) doesn't do this.

I want the client to click on the treeview entry and after I load the appropriate data from SQL into the datagrid, I want to put the cursor in the first cell of the first row. This will allow the end-user to start typing right away without having to position the cursor using their mouse.

Lost in the Vast Sea of .NET

Visit my website at www.komputing.com
 
Whilst the following piece of code:
Code:
DataGrid1.CurrentCell = New DataGridCell(0, 1)
doesn't actually make the cursor start blinking in the cell, it ahould actually give focus to the cell so that they can just start typing in the cell...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I tested this and tried to type once this code was executed and had no luck.

I put a breakpoint in to the program above the suggested logic to make sure it was being executed.

It is being executed and it is the last line of code other than an End If and a End Try that is being executed.

Any other suggestions?

Lost in the Vast Sea of .NET

Visit my website at www.komputing.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top