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




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.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Cannot Assign Values To New Datagrid Column
Hi all,

In VB6, I have a datagrid with 2 columns data fields from a database. I use coding to add a new column and it works. However, when I assign value to the new column, I got an error.

My code,

Dim ColumnCount as integer

With DataGrid1
        ColumnCount = .Columns.Count
        .Columns.Add (ColumnCount)
        .Columns(ColumnCount).Caption = "New column"
        .Columns(ColumnCount).Locked = False
        .Columns(ColumnCount).Visible = True
        .Row = 0

        .Columns(ColumnCount).Value = "new data" <-- Run time error 6147: Column not found, /1

End With

Any one knows what happened? Please help.

Assign Text Into DataGrid Column
Hi,

Anyone know how to assign the text into DataGird's columns?

For Example:

Sim s As String

s = "ABC"

DataGrid1.Columns(0).Caption = s 'This One Work Fine


Datagrid.Columns(1).Text = s 'This One Doesn't Work


Anyone know how pls reply to me thanks...

How To Assign Datasource To Datagrid ?
I use datagrid.datasource = rs. But there is a type mismatch error.

Datagrid. Assign A Different ToolTipText To Each Row.
I have a Datagrid with a defined width.It has only one column, with a width bigger than the Datagrid width.

I want that the end user can see the content of each row
completely .

1.

I tried to put both scrollbars visibles to get the end user can see all the content of the column, but the horizontal scrollbar only scroll column to column, not into a column. I don't not how can I change this.

2.
I tried too, assign a diferent ToolTipText to each row, using the event MouseMove. I get the current row using:

DG_EsqArt.RowContaining(Y)

But when the user uses the vertical scrollbar, this function doesn't work.
For exemple, in the Datagrid are visible at a time 20 rows, if the end users scroll once vertically, and clicks the row 21, the above functions return the row 1, not the 21.

Can someone help me?

Thanks,
Eva Janakieff

Assign HasChanges For Each Row In A Datagrid
Hi There
I Have A Datagrid That I Use To Fill An Invoice With ItemID, Description,Qunty,Price.

Saving And Retrieving The Invoice to and from SQL Server Is POC

How Can I Mark The Modification On Each row Or a Deleted Row , So That When I Save My Work The Software Would Recognise The Update That Has Been Done And Perform The Condition Given Correctly
my Condition In My Code That I Have Assigned In The Save Mode Are

Code:
    For Each row In InvDataSet1.Tables(0).Rows
                'Assign Values To All Parameters And Excute Querry
                With MyCom
                    .Parameters("@InvNum").Value = CInt(txtInvID.Text)
                    .Parameters("@ItemID").Value = row.Item(1)
                    .Parameters("@InvQunty").Value = row.Item(2)
                    .Parameters("@ItemPrice").Value = row.Item(3)
                    .Parameters("@InvVAT").Value = row.Item(4)
                End With
                If row.RowState = DataRowState.Added Then
                    MyCom.CommandText = "NewInvLine"
                ElseIf row.RowState = DataRowState.Modified Then
                    MyCom.CommandText = "UpdateInvLine"
                ElseIf row.RowState = DataRowState.Deleted Then
                    MyCom.CommandText = "DeleteInvLine"
                ElseIf row.RowState = DataRowState.Unchanged Then
                    MyCom.CommandText = "UpdateInvLine"
                End If

[Code]


Thank You In Advance





Edited by - wkalo on 6/21/2005 3:41:27 PM

Assign Datasource To DataGrid At Runtime
hi
I want to assign datasource to the datagrid ( or any other compatible grid..if u have suggessions pls tell me)
This is my code
[VBCODE]
Dim cst, sq As String

sq = "SELECT * from TABLE"
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset

con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open "F:Trial rial.mdb"
rs.Open sq, con, adOpenDynamic, adLockOptimistic, adCmdText

DataGrid1.DataSource = rs.Source


[/highlight]

But while executing the program i get the following error
...METHORD OR DATAMEMBER NOT FOUND

the Adodb connection etc etc works fine

Help Please, Assign Adodb.recordset To Datagrid?
hi

does anyone know how to assign an ADODB.recordset to a datagrid??

The recordset connection is made with JET OLEDB 4.0
Access 2002 db
hope you can help me, it's very urgent!!
school project!! PLEASE?

Assign Only Two Columns From Recordset To Datagrid
Hi,

I am using VB6.0, Access 97.
I am retrieving data through AdoDb.Recorset.
i am getting 4 columns, but i want to display only 2 columns in Datagrid.
Code:
EX:
  rsCheck.Open " SELECT tbl_Tax_Types.Tax_Type, Sum(tbl_TransDetails.Payment) AS Amount,
        & " tbl_TransDetails.Check_Date, tbl_TransDetails.CheckPrinted " _
        & " FROM tbl_Tax_Types INNER JOIN tbl_TransDetails ON " _
        & " tbl_Tax_Types.TaxID = tbl_TransDetails.Tax_Type " _

i want o display only Tax_type and Amount in Datagrid



Is it possible?
any help will be appreciated.
>>>>>>>>>>>>>>>>>>>>>>>>



Edited by - sreddy on 8/25/2005 8:01:57 AM

Assign ADO DataFlds To DataGrid Cols
Hello everyone
I am attempting to assign data fields from access 2003 to a dataGrid in VB6. I do not want to use the the properties wizard to assign the data, I want to do it using code. This is what I have, but the dataGrid displays blank. Col headings do display as specified. The record set is defined as such:

With rstCatPrimary
.ActiveConnection = conMMM
.CursorLocation = adUseClient
.Source = "select id, primaryCode, desc from CatPrimary"
.LockType = adLockOptimistic
.Open
End With

Set grdData.dataSource = rstCatPrimary.dataSource
With grdData
.
.
' ol Headers *******
.Columns(0).Caption = "Primary Key"
.Columns(1).Caption = "Primary Description"
'Col data assignments ****** (NEXT 2 LINES ARE THE PROBLEM)
.Columns(0).DataField = rstCatPrimary!primaryCode 'data fld = primaryCode
.Columns(1).DataField = rstCatPrimary!Desc 'data fld = desc
End With

The grid DOES populate if I use the properties wizard, so the dataset is solid

Thanks in advance

Vince

Datagrid (Visual Basic 6.0). Assign A Different ToolTipText To Each Row.
I have a Datagrid with a defined width.It has only one column, with a width bigger than the Datagrid width.

I want that the end user can see the content of each row
completely .

1.

I tried to put both scrollbars visibles to get the end user can see all the content of the column, but the horizontal scrollbar only scroll column to column, not into a column. I don't not how can I change this.

2.
I tried too, assign a diferent ToolTipText to each row, using the event MouseMove. I get the current row using:

DG_EsqArt.RowContaining(Y)

But when the user uses the vertical scrollbar, this function doesn't work.
For exemple, in the Datagrid are visible at a time 20 rows, if the end users scroll once vertically, and clicks the row 21, the above functions return the row 1, not the 21.

Can someone help me?

Thanks,
Eva Janakieff

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.

Assign Data Fields From Access 2003 To A DataGrid In VB6
this question is from my Softwear engenering and Web Devlopment Teacher
________________________________________________________________________________________________________

Hello everyone
I am attempting to assign data fields from access 2003 to a dataGrid in VB6. I do not want to use the the properties wizard to assign the data, I want to do it using code. This is what I have, but the dataGrid displays blank. Col headings do display as specified. The record set is defined as such:

With rstCatPrimary
.ActiveConnection = conMMM
.CursorLocation = adUseClient
.Source = "select id, primaryCode, desc from CatPrimary"
.LockType = adLockOptimistic
.Open
End With

Set grdData.dataSource = rstCatPrimary.dataSource
With grdData
.
.
'Col Headers *******
.Columns(0).Caption = "Primary Key"
.Columns(1).Caption = "Primary Description"

'Col data assignments ****** (NEXT 2 LINES ARE THE PROBLEM)
.Columns(0).DataField = rstCatPrimary!primaryCode 'data fld = primaryCode
.Columns(1).DataField = rstCatPrimary!Desc 'data fld = desc
End With

The grid DOES populate if I use the properties wizard, so the dataset is solid

Thanks in advance

Vince

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

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.

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.

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

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