alo,
I build a DataGrid, with an Editing-column (like is written in msdn-library and others). Well, I would like to change the size/width from the TextBoxes, which you can see if you click on the Edit-Button. These TextBoxes are to large, larger than the normal size of the columns - that seems not nice.
Has anybody a solution how to change the size from that? (Maybe if possible also to change the size from the Buttons Edit, Cancel and Update)
the problem with the textbox-field is, that's a textbox witch is created in the datagrid, if you create a editable-column...that's not a textbox separate!! so you dont cannot change some properties easily in the vb-code. i tried to use css-class (was also shown in the html-code), but this doesnt work, dont know why. I have got a css class from the grid by itself already, dont know really how to program a separate css für this textbox!!...
hi,
ok, here is the code from this used datagrid with the edit-column. I dont use the template-column, just the edit-command-column. Can be this the problem? have you got an idea for that. I also tried some possibilities with css, but nothing could help.
they explain just about everything you can do with datagrid editing. Specificaly in part 7, instead of using the dropdown list you can use a text box and specify the width there
In some cases, folks like to dynamically populate their DataGrids and have the columns autogenerate. I do this most of the time, and also had the need to adjust column width. I've seen ONE post so far in all my searching that mentioned how to do it in code, but it did not work. Below, you will see a simple function that I wrote in C# to address the issue of customizing datagrid child controls.
Right now, this can be used for textboxes, but as I'm sure you can see, expanding it would be pretty darn easy to encompass other child controls.
Feel free to use this code as is or modify to do what you want it to. Here is the sample code also, to use the function....
Example Call Statement:
Code:
AdjustDataGridTextBoxWidth(<Name of DataGrid Here>, "TextBox", 110, 4, TextBoxMode.MultiLine, 8);
The Function Code:
private void AdjustDataGridTextBoxWidth(DataGrid GridName, string SubControlType, Unit Width, int RowsCount, TextBoxMode TBMode, FontUnit FontSize)
{
if (SubControlType == "TextBox")
{
for (int i = 0; i < GridName.Items.Count; i++)
{
for (int o = 1; o < GridName.Items[i].Cells.Count; o++)
{
for (int x = 0; x < GridName.Items[i].Cells[o].Controls.Count; x++)
{
if (GridName.Items[i].Cells[o].Controls[x].GetType().ToString() == "System.Web.UI.WebControls.TextBox")
{
TextBox GridTextBox = (TextBox)GridName.Items[i].Cells[o].Controls[x];
GridTextBox.Width = Width;
GridTextBox.Rows = RowsCount;
GridTextBox.TextMode = TBMode;
GridTextBox.Font.Size = FontSize;
}
}
}
}
}
}