Row / Column gets much bigger when editing a row in grid

B

Bazza Formez

Hi there,
What determines the sizes of rows / columns / cells when a grid is in edit
mode ?

When I click the edit command of a row item, the whole grid 'bounces' to a
much larger size... and after update it reduces back again.

I have a custom crafted grid (AutoGenerateColumns = False) ... and can have
not placed any setting that would seem to cause this behaviour.

Is this a default type bahaviour ? How should I work around this such that
disconcerting size changes do not occur ?

thanks,

Bazza
 
J

John Saunders

Bazza Formez said:
Hi there,
What determines the sizes of rows / columns / cells when a grid is in edit
mode ?

When I click the edit command of a row item, the whole grid 'bounces' to a
much larger size... and after update it reduces back again.

I have a custom crafted grid (AutoGenerateColumns = False) ... and can
have not placed any setting that would seem to cause this behaviour.

Is this a default type bahaviour ? How should I work around this such that
disconcerting size changes do not occur ?

Remember that it's all just HTML.

To find the answer, create a simple reproducer. Then, look at the HTML via
View Source befoire you put it into edit mode, and then look again
afterwards.

One thing I've seen cause these problems is BoundColumn columns. In edit
mode, these generate <input type="text"> fields, but without any size
attribute. That causes the column width to change. I replaced them with a
template column (with a size attribute) and the problem was gone.

John Saunders
 
B

Bazza Formez

Thanks John.. I will try that.
Regards,
Bazza

John Saunders said:
Remember that it's all just HTML.

To find the answer, create a simple reproducer. Then, look at the HTML via
View Source befoire you put it into edit mode, and then look again
afterwards.

One thing I've seen cause these problems is BoundColumn columns. In edit
mode, these generate <input type="text"> fields, but without any size
attribute. That causes the column width to change. I replaced them with a
template column (with a size attribute) and the problem was gone.

John Saunders
 
T

Tony

Hi there,
What determines the sizes of rows / columns / cells when a grid is in edit
mode ?

When I click the edit command of a row item, the whole grid 'bounces' to a
much larger size... and after update it reduces back again.

I have a custom crafted grid (AutoGenerateColumns = False) ... and can
have not placed any setting that would seem to cause this behaviour.

Is this a default type bahaviour ? How should I work around this such that
disconcerting size changes do not occur ?

When a datagrid is in item view the widths of the columns are
automatically set to the widest necessary for the data, when in edit mode
the width of the textboxes decides the width of the columns. You could fix
the width of the columns with the itemstyle property so that the columns
are as wide as the edit textboxes when in item view.

Tony
 
V

Vanni Tomezzoli

I think this is the default behavior. I solved this problem writing the
following code in the EditCommand event, which you can adapt to your
purposes:

private void grdPolicy_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e) {

this.lblMessage.Text = "";

this.saveSelection();

this.grdPolicy.EditItemIndex = (int) e.Item.ItemIndex;
this.gridBind();
this.grdPolicy.Columns[(int) NumColumns.select].Visible = false;

// cambiare le dimensioni del text grid per l'editazione

System.Web.UI.WebControls.TextBox txt;
txt = (TextBox) this.grdPolicy.Items[(int) e.Item.ItemIndex].Cells[(int)
NumColumns.issuing].Controls[0];
txt.Columns = 10;
txt = (TextBox) this.grdPolicy.Items[(int) e.Item.ItemIndex].Cells[(int)
NumColumns.expiry].Controls[0];
txt.Columns = 10;
txt = (TextBox) this.grdPolicy.Items[(int) e.Item.ItemIndex].Cells[(int)
NumColumns.premium].Controls[0];
txt.Columns = 10;
if (decimal.Parse(txt.Text) == 0) {
txt.Text = "";
}
}


As you can realize, you can change the Columns property of the text boxes
for the columns which aren't read only. I hope this can help you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top