How to set DataGridTextBox.TabStop ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a DataGrid control with two columns.
I want to prevent the user getting into the first (left) column by the Tab
key, meaning; I need the cells of the left column to be set to TabStop =
fasle.

I found a small sample showing how to that
(http://msdn.microsoft.com/library/d...stemwindowsformsdatagridtextboxclasstopic.asp)
So I tried:
DataGridTextBoxColumn textBoxColumn =
(DataGridTextBoxColumn)m_dataGrid.TableStyles[0].GridColumnStyles["LeftCloumnName"];
DataGridTextBox gridTextBox = (DataGridTextBox)textBoxColumn.TextBox;
gridTextBox.TabStop = false;

But still the tab gets there.

Can anybody show how can I do that?
 
Sharon,

The code you showed only prevents the control that is in the column from
getting focus, it won't prevent the column from being selected through tab.
I don't think that is possible with the current grid control.

Hope this helps.
 
Hi Sharon,

Thanks for your post.

To achieve what you want, I think we can do some customize to the code. My
thought is when the first column textbox got focus, just pass the focus to
the second column. Sample code like this:
private void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt=new DataTable();
dt.TableName="test";
dt.Columns.Add(new DataColumn("column1", typeof(int)));
dt.Columns.Add(new DataColumn("column2", typeof(string)));
for(int i=0;i<5;i++)
{
DataRow dr=dt.NewRow();
dr["column1"]=i;
dr["column2"]="item"+ i.ToString();
dt.Rows.Add(dr);
}
this.dataGridTextBoxColumn1.TextBox.Enter+=new EventHandler(TextBox_Enter);
this.dataGrid1.DataSource=dt;
}

private void TextBox_Enter(object sender, EventArgs e)
{
this.dataGrid1.CurrentCell=
new DataGridCell(this.dataGrid1.CurrentCell.RowNumber,
this.dataGrid1.CurrentCell.ColumnNumber+1);
}

This works well on my side. Hope it helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top