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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help setting up a textbox within a datagrid, please?

Status
Not open for further replies.

LadyDragon

Programmer
Jan 14, 2004
24
US
I am trying to set up a textbox within a datagrid and I'm not sure how to do it. Here is the code I'm working on. I would like these cells to be textboxes that the user can modify the values and hit a save button for processing. Right now, I can set the cell text, but am unable to figure out how to make the cell a textbox:
Code:
TableRow  tr = Table3.Rows[3];
for(int j = 1; j< 8; j++)
{		
	tr.Cells[j].Text = "My text";
	TableCell tc = tr.Cells[j];
}

tr = Table3.Rows[4];
for(int j = 1; j< 8; j++)
{		
	tr.Cells[j].Text = "My text";
	TableCell tc = tr.Cells[j];
}

Looking through some code elsewhere in the app, it appears that this code snippet is working how I would like my code to work, but I don't understand what the Textbox tb line is doing. I've attempted to set my code up similarly, but get an index error on this line. If anyone can help me understand how this is working, I would appreciate it.
Code:
TableRow  tr = Table3.Rows[4];
						
tr.Cells[7].Text = "seven";
tr.Cells[6].Text = "six";
tr.Cells[5].Text = "five";
tr.Cells[4].Text = "four";
tr.Cells[3].Text = "three";
tr.Cells[2].Text = "two";
tr.Cells[1].Text = "one";

TableCell tc = tr.Cells[8];

TextBox tb = (TextBox)tc.Controls[0]; /* How is this textbox set?*/

string sav1 = string.Empty, sav2 = string.Empty;
if (tb != null)
{
   tb.Text = "test";
   sav1 = tb.Text;
}


I appreciate your help!

Thanks,
Juls
 
by default a datagrid contains columns with TextBoxes so there no need to redefine the wheel. What your code does is verifying if the column 8 is a textbox column or another type. (a textbox column is basically a table cell that has a textbox added to it's controls array - on the same principle there are checkbox columns or any other type). If it finds that there is a textbox there, it sets the text property of it to "test".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top