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

How to set width of textboxes in a datagrid using boundcolumn???

Status
Not open for further replies.

arneweise77

Programmer
Apr 25, 2002
46
SE
Hi!

I have a datagrid and want to update my database through the datagrid. When pressing the edit button on the grid, I get a editbox/textbox that´s to long/wide. This makes the datagrid look worse. How do I set the width of the textbox that comes up?

I´m using boundcolumn to get the data from my access database, but I can´t find out how to set the width of the textbox!

Please help me solve this problem.
Thanx in advanve, Arne
 
If you're "bound" and determined (sorry) to use a bound column, then the only way to do it would be to set the width in the onItemCreated event of the datagrid.

protected sub created(o as object, e as datagriditemeventargs) handles myDG.itemCreated
if e.item.itemType = itemtype.edititem then
ctype(e.item.cells(n).controls(0),textbox).width = 50
end if
end sub

if you're using vs, then when you ask e.item.itemtype, then you should get a nice intellisense box full of enumerations. I'm not sure if what I posted there is the correct enum value, but it's something close to that, and it should be obvious when you get the box.

My advice, however, would be to just use a template column to set up any field that needs to be editable. For everything but the simplest of editable datagrids, it's really the best way to go. It gives you the option to create your own editable controls (dropdown lists, radio buttons, checkboxes, etc...) and have them appear on the edit row. There are lots of good examples out there on the various asp.net websites that could go into more detail that I would here, so I'll leave the research up to you on that. Most of the editable datagrid examples show how to use a template column. You can really go buck-wild with them and make some really nice and extremely functional datagrids. They do take alot more setup, however, which is the only drawback.

good luck! :)
paul
penny1.gif
penny1.gif
 
I should know better than to say someway is the ONLY way. It's the only way I know of.

:)
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top