Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




How To Get The Column Name Of Datagrid


Is there anyone know how to get the number of columns and its corresponding name of datagrid and put it in list box or variable.

Or there's another option except datagrid which get the field name of a table.

Note: I only knew the name of the table but i dont know its field name.


Thank you very much for your reply.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Move The Cursor From One Column To Next Column In Datagrid
Hi
Everyone,    
    In Datagrid control, how the cursor move from one column to another column of the same row after updating the datagrid.
    plz anyone help me.
    
    thanking you in advance.

Add Column To Datagrid
Hi everybody; I hope one of you can help me.

I am displaying a table with a datagrid and want to add a column with the values from another table as it's contents.

Both tables have columns titled CODE. The second table has a field called TYPE that corresponds to the CODE (eg. CODE 101 means TYPE Maintenance). What I want to do is put the values of TYPE from the second table into the datagrid displaying the first table I'm not allowed to add a column into the table being displayed by the datagrid.

I'm connecting to the database thru Adodc (DISA for the first table; CODES for the second table)

I found this but when I try to populate the fields from the second Adodc (CODES) it doesn't work. I figure that's because the Datagrid1 is connected to DISA.

Private Sub AddColumn()
Dim c As Column
Set c = DataGrid1.Columns.Add(DataGrid1.Columns.Count)
With c
.Visible = True
.Width = 1000
.Caption = "type"
.DataField = CODES.Recordset.Fields("CODE").Name

'if i use .DataField = DISA.Recordset.Fields("WHATEVER").Name it
'puts the values from 'WHATEVER' into the column "type"

.Alignment = dbgRight
End With
DataGrid1.ReBind
End Sub

Any ideas?? Thanx in advance.

Set DataGrid.Column Value
Hi,

ive got a Problem with my data grid, i have a DataGrid where the Data Source is an DataEnvironment, allright it works, but now i want do add a column to that grid where i calculate fe: Column1 * Column2 but if i want to insert the value in the column with: DG.Columns(3).Value an error apears:

Column not found, |1

what have i to do to do that???

Column In Datagrid
Hi,
I have a datagrid that bind to a table. Some of the columns of the table are not editable. For those columns in the datagrid, I want to gray them out.
The datagrid property does not give enough tools for me to set up.

Please show me how.

Thank you,

Quang

Datagrid Column
On a form I have a datagrid...how do i specify the column width for each seperate column??

Datagrid Column
I don't want my identity column to show up in my datagrid. How do I control which columns I want visible and which ones I don't?

How To Add Column To Datagrid
Anyone know how to manually add a column to a datagrid.

The default value of the grid when you create the object is to only have two columns, I need 13. Thanks


Nightfox02

Datagrid Column Sum
I have a column in datagrid that displays all the prices. I want to sum up all the values from all the rows of that column and display it as a label. How can I sum up the data??

Thanks ... Bhavesh

Add Column To DataGrid
I am new to working with grids and cannot figure out how to add a column.
The grid is a DataGrid ActiveX Contol - Version 6.0. I can look at the
properties and code but cannot see where to add the column.

I appreciate your help.
Kevin

Add A Column In A Datagrid
I would like to know if it is possible to add a column in a datagrid.
I would like to have a column to describe all line in my datagrid.
By the way, is it possible to display a long text in the header on two line but in the same cell.
For example I have the text "this is my new cell"
And I would like that it display like that:
"this is my
new cell"
because I don't want that my columns have a width of 4000

Thanks in advance

How To Add A New Column Into A Datagrid ?
Hi,

I have a datagrid1 on my screen. I have a recordset myRst contains 3 fields (id, name, age). I set myRst as the datasource for my datagrid.
     set DataGrid1.datasource = myRst

Then I want to add a new column into this datagrid1, which can show info depend on the value of AGE. for example, if age < 12, show 'KID'; if 13 <= age <= 25, show 'Tenage'....
        
        DataGrid1.Columns.Add (3)
        DataGrid1.Columns(3).Width = 350
        DataGrid1.Refresh

Now i want to populate this new column using following code:

myRst.movefirst
do while myrst.eof = false
    with datagrid1
        if .columns(2).value < 12 then
            .columns(3).value = "kid"
        ......
        end if
    end with
    myrst.movenext
loop

When i ran the program, first 3 columns populuated successfully, but last column is empty, and I got following error:
        Column not found, /1

What does this mean?

 
Grace

Datagrid Column Sum
I am trying to find a way to sum the values of a column in my datagrid. I have not even found a way to isolate a single cell, row coordinate. Please help.

Datagrid Column Sum
I have a column in datagrid that displays all the prices. I want to sum up all the values from all the rows of that column and display it as a label. How can I sum up the data??

Thanks ... Bhavesh

Datagrid Column Sum
I have a column in datagrid that displays all the prices. I want to sum up all the values from all the rows of that column and display it as a label. How can I sum up the data??

Thanks ... Bhavesh

How Can I Get The Column Name Of The Datagrid
I want to get the name of the column when I double-click that column in a datagird control
how can i do it?
Thank u

DataGrid Column Width Value?
In this expression...

DataGrid.Columns.Item(iCol).Width = 1000

What type is '1000'?
Is it a Pixel, char...number.....etc....i cant figure it out......

the reason for this is I have a MSflex grid which has a column width of 20...i would like to know how to convert that number to the equiv in a datagrid..Please any help would be great. Thanks in advance

DataGrid Column Width Value
What is the Column Width Value Type.....ie... Pixels, Spaces, Points? etc...

Datagrid Column Control
I want to remove the column in my datagrid that shows the ID. How do you control which columns are visible?

Datagrid Column Width ????
I have two datagrids that are exactly the same. The only difference is that I am using them on different forms, and one of them has a filter.

My question is this.
On the first datagrid, I could write column widths like this
AppointmentsDataGrid.Columns("time").Width = 40
AppointmentsDataGrid.Columns("patient").Width = 150
AppointmentsDataGrid.Columns("Doctor").Width = 150
AppointmentsDataGrid.Columns("status").Width = 50
and the output was as I expected.

but then, on the second grid, when I write the same thing, the column widths get rediculously small. Is there a way of specifying the units used for the column widths that I have missed?

Jagdip

DataGrid - Format Of One Column
Set grdStock.DataSource = Adodc1
grdStock.Refresh
grdStock.Columns(0).Width = 900
grdStock.Columns(1).Width = 1700
grdStock.Columns(2).Width = 1700
grdStock.Columns(3).Width = 1700
grdStock.Columns(4).Width = 1700
rdStock.Columns(4).DataFormat = FormatCurrency(Price)

So I want to make column(4) with Format Currency. I tried this but does not work. Does anybody have idea how I can make this format in DataGrid?

Thanks,

Ilimax

Datagrid Column Question
I have a datagrid and would like all the cells in the first column to be "RECEIVE".
I've tried

DataGrid1.columns(0).text = "RECEIVE"

AND

DataGrid1.columns(0).value = "RECEIVE"

Neither worked

I was reading something about the DefaultValue property in my vb book that seems would work for my problem but ofcourse it has no examples. I also looked it up on the MSDN and it talks about using a Tag property, which I dont know how to use.

Datagrid Column Widths
I am using a datgrid, and looking for a way to "autosize" the column widths. Is this possible, or do I need to know the lenth of my data in order to set the column width?

Thanks

Setfocus To Datagrid Column
How can I set focus to a specific column in a datagrid

Datagrid Setfocus To Column
How can I set focus to a specific column in a datagrid.

How To Set Datagrid Column To Uneditable
Hi. I have a form contains a datagrid (with 2 fields/columns: ID, UserName) and two command buttons ("Add", "View All"). When user clicks on "View All" button, the datagrid will display all the user information (ID 1 to 10) with the "ID" column/field is NOT editable. When the user clicks on the "Add" button, a new row (ID = 11) will be APPENDED as the last row in the current datagrid. In this case, user can add or modify this NEW appended Row (which mean ONLY the row with ID =11 is set to editable) while ID =1 to 10 is NOT editable also. I have use the following methods to make the new row(ID = 11) to editable but to no avail.

Any suggestion is truly appreciated.


Code:
'at form load
datagrid.column(0).locked = true

'when user clicks Add button
datagrid.CurrentCellModified = True
datagrid.EditActive = True

Datagrid Column Question???
Hi Guys,

I have a datagrid which has 5 column only and more than 500 rows. Now I want to Update only 4 th column I wrote update sql statement, but after updating the data I want to refresh only updated Row (other row should remain the same ) and cursor should go to next row on 4th column. Can anybody help me with this???

This is very urgent. please help me.........

Thanks in advance,
Ekta

Datagrid Column Sizing
I am trying to size the columns of a datagrid in VB6. I have placed a datagrid on a form and use

set r=new ador.recordset 'create disconected recordset

and

r.fields.append "col name", adVarChar, 500

to append columns.

There are currently 16 columns i use and no matter how i try i cannot get the columns to the size i want, each column needs to be a width that i specify. All columns seem to be of a size that i cannot determin the source of, its not the defCol widths or any value i can see any where else.

Any suggestions would be very much appreciated.

Datagrid Column Header
Hi all,
the text I have in my column header for my datagrid is too wide for the column width I am allowed. I have used vbCrlf to wrap the text but then I cannot see the second line in the column header row. Is there a way of setting the height of the column header row? Or alternatively is there a better solution to my problem? Any help would be greatly appreciated.

DataGrid Column Format
I want to format DataGrid column (type boolean) to display
'OK' for value 'True' and 'WRONG' for value 'False'.
DataSource is set in run-time mode as:

With DataGrid1
Set .DataSource=rst
End With

I can't format column in design-mode because there is no
column numer in Custom dialog for DataGrid1 properties.

Assign A Value To A Column In A Datagrid
This should really be easy.

I have a datagrid bound to a datasource. One of the column in the datagrid is not bound to a column in the datagrid.

I would like to assign a value, or be able to edit that column like so : grdDataGrid.Columns(3).Text = "Please Work"

Please see attached project (install in c: est1n).

Click on command1 to reproduce problem.

How To Add A Combobox For A Column In A Datagrid
Hi there..
How to add a combobox for a column in a datagrid or dbgrid ..for example in the access tables you can have a pull down list/menu..

The way i add a combobox for a datagrid or dbgrid is to add a separate combobox to the form....

if dbgrid/datagrid has column named product id, when the the user clicks on the column the combobox .left and .height and .top is set to the values of the datagrid.

what it does is it positions the combo box on top of the column in the datagrid.. unfortunately this is not a very easy way of doing..and it does not look good..

is there any other way for me to add a combo box to the datagrid.. doesnt the datagrid/dbgrid has a built in sort of combobox..

Thanking you guys in advance for helpig out..

regards pragash..

Column Lock In Datagrid
is there a way to disable columns at run time in a data grid based on a recordset. i need to build a grid where different departement can view all the grid but can only write in some column depending on the departement.

thanks for any advice


I'll be among the best soon, very soon!!!

Datagrid Column Titles
Ok... I have a datagrid that is attached to an ado control... is there a way of changing column titles after I've sent a query to the ado?

Tag/boolean Column In Datagrid
Can someone show me a sleek way to set a tag/boolean column in the datagrid. I want to accomplish the same task a checkbox would have: the user selects certain records (by putting 1 into the Tag column) and then a new table is created from those records chosen.

The way I have it now partially works. This is my code.

'puts the records user selected into new table
ACCESSdb.Execute "SELECT * INTO [Chosen] FROM [Type] Where Tag = '1' "

ACCESSdb.Execute "UPDATE Type SET TAG = '' where Tag <> ''"
'this resets all the Tags back to nothing

With rsFLEETS2
.ActiveConnection = cn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open "SELECT * FROM Chosens ORDER BY TYPE ASC"
Print .RecordCount
End With

Set Adodc2.Recordset = rsFLEETS2

This works, IF the user changes the value to 1 and moves off that record. I guess the grid needs that to refresh. If the user changes the Tag to 1 and clicks on Select right away (without moving off the record), it won't return anything.

Does anyone have any idea who I should be doing this?

Summing Up The Column Of A Datagrid
Hi again, this is my recent post since July.

Anyway I have a stupid question to ask:

I have a datagrid populated by a dataset (which was filled by a dataadapter) and I want to know how do I sum up the values in a column (column no. 2 for instance) of the datagrid with a non-fixed number of rows and put the results in a variable for instance. Its that simple, the datagrid is read-only so I dont have to update the data grid, its just the adapter filling up the values from time to time.

I have just learned by browsing that it is not possible to run SQL commands into a dataset and it follows a datagrid. is this true?

I have searched this site for answers but it seems i cannot find the correct thread. Please somebody help me with my problem.

Datagrid DropDownList Column
Hi,

I'm populating a Datagrid with database values. I have an Edit button column, and what I want to achieve, is that after it's clicked, one of other columns' fields is shown as a Dropdownlist (instead of a Textbox). The values defined in the Dropdownlist do not correspond to any values from the database (they should be fixed values).

I've searched through the web, but I don'y know how to bind such List to one of the columns after the edit button has been clicked. I know this will have something to do with a Datagrid Template Column and Datagrid ItemDataBound event, but I can't seem to work it out.

Can you please help me?

How To Resize A Column In A DataGrid
I need help again, how can i resize a column in a DataGrid, i know that in the MSHFlexiGrid i can do it with

Code:
MSHFlexiGrid1.ColWidth(index) = 'a number
but there is not such property for a DataGrid.

Resizing Column In Datagrid
how do you resize a column of a datagrid to match the length of the text in it? and is it possible to change the style of the header to bold? thanks

Third Column Of A DataGrid To Show The Value Of ....
Dear Friends,

I am using MS Access Database. The following are the complete details:

Table: Balance

Fields: 1) Received
2) Sold

DataGrid: dbgBalance

CommandButton: cmdShow_Balance

I have three columns in the DataGrid. First column to show the value of “Received” field, the Second column to show the value of “Sold” field and the Third column to show the balance for which there is no field in the table.

So, what I need now is, the Third column should get the value from “Received” field and deduct the value of “Sold” from it and then show the resulted value in DataGrid Column “Balance”.

So, each row in a DataGrid will show the values like this:

1st Row : 5000 – 2000 =3000
2nd Row : 7000 – 6000=1000
3rd Row : ………………….
4th Row : …………………..
…………………………….

And so on ….

How can I do this? Please do help.

Regards,

Margaret

Get Column Headers In Datagrid
Hi all!

I would like to ask if anyone knows how to get the names of the column
headers from a datagrid?
My grid is populated at run from an excel file. So the column names are not defined at design time.

Please help.

DataGrid(Ocx) Column Validations
Hi,
I am using the following code to display 2 columns from a db via datagrid1. I have locked the first column.In the second column i am allowing the following charcterrs
a-z,A-Z,0-9, and space

I am using the cursor type as batchoptamastic, so that after clicking one button in the from update/undo the changes made in the table.

And I my aim is to restrict the second column entries only upto 10 charcters only.If the entries exceed the 10, the nothing should be allowed in the particular column.For better reference I have attached a screen shot.



VB Code:
Private Sub DataGrid1_KeyPress(KeyAscii As Integer)    Dim strval As String    strval = "abcdefghijklmnopqrstuvwxyzABDCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "                   If KeyAscii > 26 Then                If InStr(1, strval, Chr(KeyAscii)) > 0 Then                    KeyAscii = KeyAscii                Else                    If KeyAscii = 8 Then                        KeyAscii = 8                    Else                        KeyAscii = 0                    End If                                End If            End If     If Len(DataGrid1.Columns(1).Text) = 0 Then            End If End Sub

DataGrid - Column Questions
I am new to Visual Basic 6.0 and need help with the DataGrid control.

I am trying to:
1. Have data in one of the grid column's that is in "lower case" forced to "upper case"
I have tried using the Before Update event, but cannot get it to work.
2. Have column validate data. Only allow for example an "A" or "C" as valid values for a column.
3. Put in "tips" on top of each column to display information about the column itself.

I have searched the web and looked in 3 book stores and cannot find books with Datagrid examples for what I need.

Any help would be greatly appreciated.

Thanks.

Scott

How Can I Hide A Column In A DataGrid?
Dear Friends,

1. How can I hide a column (here for example I dont like to view "cusnum" column in a form at run-time) from DataGrid.

2. How can I change the labels of DataGrid (for example I would like to change "fname" & "lname" to 'First Name' & 'Last Name'

Please help me in this regard.

sweetie_2005

How To Set Datagrid Column To Uneditable
Hi. I have a form contains a datagrid (with 2 fields/columns: ID, UserName) and two command buttons ("Add", "View All"). When user clicks on "View All" button, the datagrid will display all the user information (ID 1 to 10) with the "ID" column/field is NOT editable. When the user clicks on the "Add" button, a new row (ID = 11) will be APPENDED as the last row in the current datagrid. In this case, user can add or modify this NEW appended Row (which mean ONLY the row with ID =11 is set to editable) while ID =1 to 10 is NOT editable also. I have use the following methods to make the new row(ID = 11) to editable but to no avail.

Any suggestion is truly appreciated.


Code:
'at form load
datagrid.column(0).locked = true

'when user clicks Add button
datagrid.CurrentCellModified = True
datagrid.EditActive = True

Datagrid Column Width
Hello everybody

I`m using a DataGrid component in my application. The Grid is being populated from an ADODB Recordset object. The problem is that some data fields are longer than the default width that the DataGrid components sets. How can I tell the DataGrid component to automatically adjust to the width of the data?

thx, in advance

George Papadopoulos

DataGrid Column Color Help
I have a DataGrid with some columns locked and some not. I would like the unlocked columns to have a white background in the rows and the locked columns to have a grey background.

Is this possible? I can't seem to make them different they seem to all have to be the same color

Thanks for any and all help.

Datagrid Column Total
Hello
Any One Help Me?
I have 4 columns in grid
1 itemname
2. Price
3 Qty
4 Amout
I want to amout = price*Qty at time of type value

DataGrid Column Total
Hello
Any One Help Me?
I have 4 columns in grid
1 itemname
2. Price
3 Qty
4 Amout
I want to amout = price*Qty at time of type value

(solved) Err... Datagrid Column
I wrote an small sub to autoresize the columns of my datagrid, but it has an little error... it doesn't work

What did i do wrong, when i run this vb will freeze and 30 seconds later it works again but nothing happend to my colums :/



VB Code:
Private Sub Command5_Click()On Error Resume NextDim StrSize As IntegerStrSize = 0 For i = 0 To dGrid.ApproxCount - 1          dGrid.Row = i     For J = 0 To dGrid.Columns.Count - 1    dGrid.Col = J        If TextWidth(dGrid.Text) > StrSize Then            StrSize = TextWidth(dGrid.Text)            dGrid.Columns(J).Width = StrSize        End If    Next Next End Sub

Copyright © 2005-08 www.BigResource.com, All rights reserved