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!

Datagrids

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
If your wanting to only show one record from a database that has many columns can you use a datagrid that will put each column into its own row? How would you do this?
 
I could be mistaken what you are asking. What you want your datagrid to do is something like this:

database table
---------------------------------------------
ColumnName1 - ColumnName2 - ... - ColumnNamen
entry1 - entry2 - ... - entryn

datagrid
------------------
ColumnName1 entry1
ColumnName2 entry2
... ...
ColumnNamen entryn

Is this what you want?
 
Hmmm...there might be a cleaner way, but off the top of my head here's how I would tackle it:

1. Return the datatable holding the row of information
We'll call this one dtData

2. Create a new datatable object, adding one column to it
(call it whatever you'd like). We'll call this dtEmpty

3. For each field in dtData, I would take that value and
assign it to a new datarow's item(0) value, which I would
then add to the dtEmpty data table.

4. Once I had all the items in teh dtEmpty datatable, I
would bind my datagrid to dtEmpty.

Voila! In theory, you'd have a vertical datagrid view of the
record.

:)

Jack
 
I believe the datalist has a property that allows you to view records vertically rather than horizontally That'l do donkey, that'l do
[bravo]
 
I also need the user to be able to edit this. I know that the datagrid supports that, but does the datalist?? I like frost10 suggestion, but could you edit it then? What do you suggest? Datalist or Datagrid?
 
If Datalist (hardly worked with them) can do it, then go for it.

Worst case, you could do the datagrid way.

Um, just a third thought too though:
If you want the users to be able to edit it, why not just create a user interface out of textboxes instead of using a datagrid? You coudl create an object that holds the record values, and just drop the values into the textboxes.

Just a thought anyway

Jack
 
I think that is a great idea, but the reason I was thinking of using a datagrid was because I wanted to display the user there current information and then have an edit command incase they wanted to change something. So everything could be on one page
 
could still be on one page.

Textboxes have a ReadOnly property.

When the data is displayed, you could have the textboxes to be in ReadOnly mode. When they click edit, it unlocks all the fields so they can edit them.

1 page, no datagrid crap to worry about.
:)

Jack
 
So it would be something like this

Sub EditCommand()
texbox1.readonly = False
texbox2.readonly = false
End Sub.
Like That?
 
yup, pretty much.

If you wanted to get super fancy, you could even change the look of the textbox between viewing and editing (so like the textbox would look like a label or soemting for viewing, but when you click edit it would look more like a text box).

There's alot of stuff you can do with the interface, but yeah, thats how you'd set the read only
:)

jack
 
I do like your example of

1. Return the datatable holding the row of information
We'll call this one dtData

2. Create a new datatable object, adding one column to it
(call it whatever you'd like). We'll call this dtEmpty

3. For each field in dtData, I would take that value and
assign it to a new datarow's item(0) value, which I would
then add to the dtEmpty data table.

4. Once I had all the items in teh dtEmpty datatable, I
would bind my datagrid to dtEmpty.

Do you not recommend doing this?
 
wouldn't this be done with simple css to change the look of the textbox??
 
Truthfully, I'd to teh textbox thing if it was only ever going to be for one record at a time.

And yeah, you could look at doing it through the CSS. problem is that CSS is mainly look-wise stuff, whereas items like the textbox's ReadOnly property can't be accessed that way (to my knowledge anyway), in which case you'd need code behind.

All of our edit screens in our webapplication use the textbox version, and not direct editing within datagrids.

Jack
 
If your not using CSS, then how do you make it look like a label in the read only mode? what do you change to make it look like a textbox then when editing?
 
Truthfully, I'd to teh textbox thing if it was only ever going to be for one record at a time.

And yeah, you could look at doing it through the CSS. problem is that CSS is mainly look-wise stuff, whereas items like the textbox's ReadOnly property can't be accessed that way (to my knowledge anyway), in which case you'd need code behind.

All of our edit screens in our webapplication use the textbox version, and not direct editing within datagrids.

Jack
 
sorry, didn't mean to post that twice.
:)

K, Textboxes have a slew of properties that you can change. For instance:

With TextBox1
.BorderStyle = Solid
.BorderWidth = 1
End With
Will give you a text box that has a solid border, and doesn't have the traditional ridged/grooved (always get those mixed up) border.

If you set
With TextBox1
.BorderStyle = NotSet
.BorderWidth = Nothing
End Width
Then that gives you back the regular text box.

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top