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

Customizing DataGrid

Status
Not open for further replies.

sisan

Programmer
Jan 9, 2002
39
ID
Somebody please help me

My DataGrid (not the two others grid) control binded to an Adodc control. I want to customize it by coding, not at design time. Say, I have 5 fields in the ADO table, but only 3 will displayed in the DataGrid's rows, and then the titles of the rows will be changed, too.
Can I do this ?

Thank you...

-Sigit-
 
Either select only the 3 fields in the recordsource of the DataControl, (and you could the use an Alias column name in the Select statement), or

Use the Standard Formating object and set each column to it's own format type, or, after the grid is loaded with the data, change the properties:

With DataGrid1
.Columns(0).Caption "NewColumnName1"
.Columns(1).Caption "NewColumnName2"

.Columns(0).NumberFormat = "##.##"
.Columns(0).NumberFormat = "Mm/Dd/yyyy"

End With [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks CCLINT,

I use the Standard Formating object, because the other fields still be used (although not displayed). How to select only the desired ones?

OK. Maybe I can use the .Remove(), but how if the fields is much more than 3 and the columns number I want to display is randomized. I try to remove all fields then add some, but couldn't work.

Any idea ?
 
You could set the visible property of the column that you do not want to false:
datagrid1.Columns(0).Visible

Better would be to select only the fields that you need by changing the recordsource of the data control:

SELECT Field1 AS [Column One],Field5 AS [Column Two] FROM myTable

For the Standard Formating use:

(add a reference to the "Microsoft Data Formating Object Library"

Dim stdDATE As New StdDataFormat
stdDATE.Format = "Mm/Dd/yyyy"
Set DataGrid1.Columns(6).DataFormat = stdDATE

You can also loop through the Grid columns collection and inspect each field to find out the data type:

Dim col As Column

For each col in DataGrid1.Columns

Select Case Adodc1.Recordset.Fields(col.DataField).Type
Case rdbDate
Set c.DataFormat = stdDATE
End Select
Next fld

Also, you can only use the .Remove method of the recordset if the recordset is diconnected from the data source:
Set Adodc1.Recordset.ActiveConnection = Nothing

I'm really not quite clear as to what you want and how you have your data set up, so it is a little hard to help, but as you can see above, there are plenty of possibilities to get where you want to go.

[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thank's again, CCLINT, your suggestions are helpfull to me, even more. (I didn't know how to format Date datatype in grid's column before).
-Sigit-
 
I made option button on my VB6 form, can somebody help me put that option button on sql field which connected to that form???
 

Sdjuhans:
1. Please start a new thread with your question.
2. Be a little more clear as to exactly what you are trying to accomplish and how you have your data set up. [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top