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

Datagrid Show Values

Hi peepz, I have a Datagrid which is filled by a recordset.
Now i want to add the value of the row i click on to a textbox, but this isn't done correctly, i have t click twice because the first time i click on a row it's "selected" and the second time it cahanges the value of the textbox.
Private Sub Datagrid_Click()
txtField.Text = rstRecordset.Fields(0)
End Sub
can anyone tell me a way to do this right ?

Or is it possible to sellect full rows only ?

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Show Hex Values?
Hi all,
I need a example to generate a hex value.I need to assighn constant values for a variables and depending on the user selection I need to add them and total will be stored as Hex value.I don't know what data type I have to diclare all variables.I will give example can any one send code for it please?.


Dim FirstVariable as ..........
Dim Second Variable as ........

FirstVariable = 0X0008
SecondVariable = 0X0040
ThirdVariable = 0X0002

Ehen I add all these Result should be 004a.

Could anyone tell me what datatype I have to declare and how to convert the total??

Show Different Values On Click
I have a button that has three values, DEG, RAD and GRAD. In the default state the DEG is visible, the RAD and GRAD are set to invisible.

If I click the button once, I need it to change to RAD and if I click it again switch to GRAD and then finally if I click again switch back to DEG.

Whats the best way to do this?

Do Not Show Repeating Values In A Query
In Access, I have a table that shows part numbers. These parts can go to multiple customers, so they can be repeated in the table.

What code would I put (SQL is fine) in my query to display each part only once, despite how many times the part may appear in the query?

Show Values Dbgrid In Label
hi all,

got a little problem again. i've searched the forums but i couldn't find an answer. when my dbgrid is filled with values from a table, i want users to select a row and then i want the values of that row (customerid, customername, ...) to be shown in a label.
i've tried something like:

Private Sub DBGrid1_Click()
Label1 = DBGrid1.Row
End Sub
but that only shows the rowid. how can i let for example just the customerid to be shown in the label? i tried: label1 = dbgrid1.row(customerid) but that didn't work out, gives error

thx in advance

Take Values From Registry And Show In Listview!
How can I read all the values names and their values from a given registry folder and show them in a listview? I have declared the variables needed to read the registry as follows:


Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long

Private Const REG_SZ = 1
Private Const LOCALMACHINE = &H80000002 ' This is really HKEY_LOCAL_MACHINE

I know to read a value from a registry, the following command is used (It will take the value of item "Username" from the registry folder "HKEY_LOCAL_MACHINESOFTWAREMy ApplicationLogin" and show it in Text1.Text ):


Dim nBufferKey As Long, nBufferSubKey As Long
Dim nBufferData As String
nBufferData = Space(256)

RegOpenKey LOCALMACHINE, "SOFTWAREMy Application", nBufferKey
RegOpenKey nBufferKey, "Login", nBufferSubKey
'======== TAKE FROM REGISTRY ===========
RegQueryValueEx nBufferSubKey, "Username", 0, REG_SZ, nBufferData, Len(nBufferData)
Text1.Text = nBufferData

What I want to do is to read all the values in a given registry folder and show all these in a listview. There may be many many values in this folder. When the form loads, I want to list all these value names alongwith their values shown in a listview in two columns. Thanx in advance !!!

Mschart Show Values Like Excel
I am using mschart to draw temperature against time, with the time being anywhere between minutes to days from an access database and would like to have the feature like excel where if you select the point on the graph you can display the value of the point does anyone know how to do this ?

Variable Values Won't Show In Step Mode
When running an app from the IDE in step mode you can hover the mouse over a variable's name and its value shows up as tooltip text. The problem is it wasn't working for me today and I don't have a clue.

Show RGB Values For Custom Color? [RESOLVED!]
Ok last thing needed to complete my app. I decided to let the user choose a custom color from a dialog box. (My app is a Color grabber program).I can open the color dialog fine, and when its closed show the correct color in the picpreview. The problem is after i have closed the color dialog it doesnt move my RGB scrollbars and show the current values Here is my code:

VB Code:
Private Sub cmdCustom_Click()'Let user choose custom colorDim r As IntegerDim g As IntegerDim b As Integer'I was experemting here, so more than likely will need changingr = RGBScroller(0).Valueg = RGBScroller(1).Valueb = RGBScroller(2).Value'Open the color dialogdlgColor.ShowColorpicPreview.BackColor = dlgColor.Color'Need to show correct scrollbar position here for the RED, GREEN and BLUEEnd Sub


Retaining Variable Values Through The FrmAbout.Show
I added an About form to Help off the menu. It comes up, you click ok and return to the main form only to find some variables empty and some variables retaining their values.

I resorted to putting all the variables that had been declared in the main into the module as a public but I still got the same result, some variables empty, some unaffected.


How To Show Row No On Row Header In Datagrid?
Hi, does anybody know how to show row No (1,2,3.4..)on row header of each row in DataGrid? Thanks a lot

DataGrid Will Not Show Data
I have a program which used a data enviorment and need to do a custom query against the database. Instead of creating a new connection and everything I just use the one available thru the Data Env. That works but my problem is the datagrid will not display the data. Here is a some of the code

Dim rs As ADODB.Recordset
Set rs = dEnvEA.Connection1.Execute("SELECT * FROM dbo.ShAgents")
MsgBox rs.RecordCount
MsgBox rs.Fields("AgentID")
Set DataGrid1.DataSource = rs

When the program is run I do see the correct info from the recordcount and the AgentID fields so the recordset is there and filled but I just cant display the data.

Show The Query On A Datagrid
I can show a table of a database file on datagrid control (I have used an ado data control to connect database).
But I have created a query with a long sql command on MS Access.
How can I show that query on a datagrid on my VB project?

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.



Datagrid Does Not Show Any Records
Two parts of question :

VB Code:
private sub Form_Load()      call batch_process  ' insert data to tblBatch_Load      Datagrid1.Refresh end Sub

When batch_process is done,

1) there is no record displayed even using datagrid.Refresh

2) how to print the records from datagrid on the hard copy?


How To Let Highlighted Row Always Show In The Datagrid?
I have a MSFlexDataGrid, the user may scroll it to bottom, so the first row which is highlighted can not been seen from the screen.

now, the user press the buttom 'add', my program will add one row at the top and highlight the first row (added row). I want the datagrid automatically scroll back so that the first row can be seen from screen. How can I do that?


DataGrid Not Show Datas
Hi ! I am Hira.
I am learning how to use DataGrid control.
I want to show datas from MS Access table on the DataGrid.
But I could't do that.

Please give me some advices for resolving this problem.
I have confirmed I can connect my VB application with Access DB. My code is as bellow.

Private Sub Form_Load()

    Dim MySql As String
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
On Error GoTo Err_Form_Load

    cn.ConnectionString = "XXXXXX"
    MySql = "SELECT MachineNumber FROM MachineData"
    rs.Open MySql, cn, adOpenStatic, adLockOptimistic

    Set dbgTrouble.DataSource = rs
    Exit Sub
    MsgBox (Err.Number & Chr(13) & Err.Description)
End Sub

Show Picture In Datagrid

I have a access database which is linked to vb6 with a adodb control and viewed with a datagrid control. The information shown is as follows:

Log   Name
-1    Smith
0     Jones

The log column can only be -1 or 0. So what i would like is in the datagrid, the -1 or 0 to be replaced with a picture. -1 to be one pic and 0 to be another. Is this possible?

Thanx for any help you can provide.

Does DataGrid Show Checkboxes?
I'm new to VB so I'm trying to figure out the best control to use to do the following: A user will find a customer ID and then see a listing of open invoices with some details (date, description, etc.). Then the user can input a Purchase Order (PO) number into a textbox and choose which invoice(s) the PO can apply to. I'd like to have the user be able to mark a checkbox next to the invoice(s) that the PO will apply to. Then Hit OK to save the PO number into the Invoice record. (The database is SQL 7.)

I thought the DataGrid control was the best choice of what comes with VB 6 but I can't figure out how to get a checkbox into the DataGrid.

If I go to the form with the DataGrid, select the DataGrid and right click, and select Properties, I get the Property Pages tab control. I select the Format tab, and then select the column I want to be a checkbox, and then select Checkbox from the list of possible formats. To the right of this choice, the "Help" says "This format allows a checkbox to be set properly when bound to a boolean column." I'm not sure what that means. What I want is to see a checkbox when the data displays.

My datasource is an ADO Data Control which has as its data source a SQL stored procedure. The column that I want to show as a checkbox is of datatype bit.

Can this be done with the DataGrid Control? I would prefer to not have to buy a third party component if it can be done reasonably easily with the DataGrid Control.

Thanks for any help/suggestions you can provide.

Cathy Johnson
Oakland, CA

How Can I Show The Selected Row In Datagrid
i want to show current row which is the result of my query in datagrid
how can i do ?
In MSDN it is written "The data in the current row can be accessed using the Bookmark property"
ok it works but i want to set datagrid like datagrid1.bookmark =i but it doesn't work
also datagrid1.row is not the property that i want to use .

Three Options To Show In Datagrid, How?
Hi I have a table Parts, a table PartUsage and a UI that allows the user to pick a Part, a Part Category, or all Parts and show the resulting PartUsages in a DataGrid. The all Parts works fine using SqlDataAdapters for the tables and a relationship in the schema. I change the Parts adapter selection to add a parameter for either a Part or Category. I have set up relations for the other choices. When I try to use the Part Category or a single Part I come to grief with exceptions for arguments. I am supplying a value for the parameter.

[code] For Example:
            daParts.SelectCommand.CommandText = "Select * From Parts Where PartID = @partid"
            daParts.SelectCommand.Parameters.Add("@partid", SqlDbType.Int)
            daParts.SelectCommand.Parameters("@partid").Value = intPartID

But when I try to do the same with the PartUsage table I get a error

                    daSelectPart.SelectCommand.Parameters.Add("@partid", SqlDbType.Int)
                    daSelectPart.SelectCommand.Parameters("@partid").Value = gblintPartID
                    DataGrid1.DataSource = DataSet11
                    DataGrid1.DataMember = "PartsSelectPartUsage"

An unhandled exception of type 'System.ArgumentException' occurred in

Additional information: Cannot create a child list for field PartsSelectCategoryUsage.
What am I doing wrong? Am I doing anything right? TIA

Datagrid Does Not Show All Records

My first time to ask here. I got a VB6 program that shows records in a datagrid "dtg". The datasource property of dtg is an adodc object named "adg".
Here's the code.


Private Sub Form_Load()
Dim strSQL As String
Dim i As Integer

strSQL = "Select * From table"
adc.ConnectionString = TempDB.ConnectionString
adc.RecordSource = strSQL


end sub

The problem is it does not show all records in the datagrid. Will I set a delay for an event?

Thanks in advance

How To Let The Records Show Up Immediately In The DataGrid?
Let's say I have a form which adds data into the Recordset; this recordset will be displayed in the Datagrid.

But the problem is, the added data do not show up in the datagrid immediately; the user have to wait for a while before the data appears in Datagrid.

Are there any ways to let the data appear imeediately in the datagrid?

How to solve this problem?

Please Advise. Thanks a lot.

Table Contains Data But Datagrid Does Not Show It
i want to use a datagrid to display the data from a table.

the gets it contents from another table. i use the sql statement INSERT INTO for this.
when i look in acces i can see that the table is populated, but the datagrid only shows the names of the fields and not the data in the fields..

the code:


Private Sub Form_Load()
Dim strSQL As String
Dim datastring As String
' hieronder worden de trades die bij het CUSTUMORID van de desbetreffende klant horen, geselecteerd en
' daarna in de tabel TEMP gezet.

Text1.Text = voornaam
Text2.Text = achternaam
Text3.Text = rekeningnummer
Text5.Text = klantid

Label4.Caption = Date

Set db = OpenDatabase("C: ooltjedb1_97.mdb")
Set rs = db.OpenRecordset("Trades", dbOpenTable)
Set rs1 = db.OpenRecordset("Temp", dbOpenTable)

db.Execute (" delete * from Temp")

datastring = "INSERT INTO Temp (soorttrade, [start price], [end price], [stop loss], [volume], [traderesult]) select soorttrade, [start price], [end price], [stop loss], [volume], [traderesult] from Trades"
db.Execute (datastring)

datastring = "select * from Temp"
'datastring = "select [soorttrade], [start price], [end price], [stop loss], [volume] from Trades"
Data1.RecordSource = datastring

Text8.Text = rs.Fields("volume")

End Sub

Show Datagrid After Closing Connection, Possible?
Hello everybody,

Could any one help me with that problem?
I coded as:

Call ConnectMainDB
Dim dtg1 As ADODB.Recordset
Set dtg1 = New ADODB.Recordset
Dim dSQL As String
dSQL = "SELECT WO_Number,sender_name,issue_date,Description_Of_WO,Region,Service_Node,Parameters_Involve,Patch_Attached,Patch_No,Date_Of_Implementetion,Implemented_Dpt,Implemented_By FROM main_table ORDER BY ID DESC"
dtg1.CursorLocation = adUseClient
dtg1.Open dSQL, con, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = dtg1
If dtg1.RecordCount > 0 Then
Dim hg As String
hg = dtg1.RecordCount * 255 + 400
If hg > 9180 Then hg = 9180
DataGrid1.Height = hg
DataGrid1.Visible = False
End If

that shows data in the datagrid all right. But if i append the code to close the connection

call closemaindb

data from the data grid disappears.

connectmaindb and closemaindb are two functions defined by me.

Now the reason that i want to close the connection is that when i call the connectmaindb afterwards, there is an error message "the connection is already open."
So i need to close the connection before i can call the connection function again but still be able to show the data in the data grid.

Anyone there to help!

Show Records Into Datagrid, Too Slow
Dear Expert,

I am using ADO to connect to Oracle 8i, too slow when showing records into datagrid.. why? .. does any body has experience on this?

Thanks & Regards

How To Show The Particular User Details In Datagrid
Hi all,
Can anyone tell me how to get a record for particular user or Number
In my sql i,v Pinvoice table following fields
InvNo int1001
Descrption varchar(20)Fan
Price float
so my question is if type the InvNo in a textbox this all records i need to display in a grid if i type the another Invno then it has to show me the corresponding InvNo Records in the same grid or else In a button Previous Or Next it show me like this and in below the Grid i need the total for theGross amount , so can anyone tell me how to do this

Show Records Into Datagrid, Too Slow
Dear Expert,

I am using ADO to connect to Oracle 8i, too slow when showing records into datagrid..  why? .. does any body has experience on this?

Thanks & Regards

Show Negative Numbers In Datagrid
I'm using VB6, Access 2000 and ADO.
I show the result of a recordset in a datagrid. As some numbers are negative numbers, my cliente would like to see these numbers between parenthesis and in red.
Do anybody has any ideia about that? I can send the fragment of the code if necessary.
Best Regards
Julio Borges
Rio de Janeiro - Brazil

Show Check Box In DataGrid Control
How can I show check box in a datagrid control ?


Data Report With Group Section Doesn't Show Updated Values.
I have a datareport with group sections (group headers and group footers). At first, I've created a data environment wherein I've defined the fields that is used for grouping. The data environment is connected to a temporary table wherein values are added dynamically. My problem is everytime i show the data report it doesn't show the updated values of the table. Can anyone help me with this?

Before I am not using a data environment but instead i am using ADODB.recordset and assign it directly to the data report. But for this case, it doesn't work since I am grouping some fields... does anybody know how to make a data report with group section without using data environment? (instead using ADODB)

any help will be greatly appreciated. URGENT!

Would Like To Connect A Datagrid To Table And Show Information
I have a form with a datagrid entitled: grdDataGrid

I want this grdDataGrid to display certain fields from a table named DISP

I'm taking the first step in learning how to do this by just connecting grdDataGrid to the table DISP itself.

I have the following code:

Private Sub Form_Load()
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & SERVER & "disp-1_be.mdb;Persist Security Info=False"
Set rst = New ADODB.Recordset
rst.Open "DISP", cnn
Set grdDataGrid.DataSource = rst

End Sub
And I keep getting an error: Run-time error '7004'. The rowset is not bookmarkable.
Please urgent help.



How To Show On DataReport The Record Chosen In Datagrid
How To Show on DataReport THe record that i choose in datagrid ?

i use ADO.Recordset

dim adors as new ADO.Recordset

set datagrid.datasource = adors
set datareport.datasource = adors
i put text1.datafield = name . text1.datafield is on datareport.
name == field name in recordset.
The Problem is datareport show all the name.
Not The one that i choose (clicked) in datagrid.

Is there Anyway to do it ?

Thanx ...

When i sort date in datagrid, there's an error :
run-time error : 3001
arguments are of the wrong type, are out of acceptable range, or in conflict with one another.
But i can sort the rest of the field. Except the date.
I use DateTimePicker To input the date into recordset.


Datagrid Doesn't Show A New Or Modified Record.
I created a VB6 front-end that connects to a SQL Server database. The front-end has a DataGrid that is connected to a table in the database via a ado recordset object. The datagrid does not show records that I have "programmatically" add at run-time to the underlying recordset (datasource of the datagrid).

My goal for the functionality of the datagrid has three parts
1. To display a new record that was created (added to the recordset) at run-time using data that I select in various controls on the form.
2. Display any field/column changes performed programmatically to a/the record in the recordset during run-time.
3. (Very Important) I am also looking for away of not saving any of the modified or new records unless I click on a "Save" command button (If I truly wish to save the modified/new records when I am ready to close/exit the front-end.

Datagrid Doesn't Show A Record That Is Added
I created a VB6 front-end for an Access database. The datagrid does not show records that I "programmatically" add at run-time to the underlying recordset (datasource of the datagrid) unless I close the form with the datagrid and open it again.

My goal: I am trying to create a new record at run-time using data that I select in various controls (e.g. listboxes) on the form, click an "Add" command button and see the newly created record in the datagrid.

I tried datagrid methods such as refresh, rebind, etc. Nothing seems to work.

DataGrid Control CheckBox Show Problem...
Hi gurus,

Actually I'm facing a typical problem with the CheckBox in a DataGrid Control. I have created table which contains a boolean field. After connecting through the ODBC Data source control I supplied the data source to the DataGrid Control. There is only one column in the Control. Setting the format of the specified column to checkbox (no such checkbox like access table view) is coming. So, can you please help me to show the check box in a column of a DataGrid Control ???

Thanks again.

Get Row Values From Datagrid?
How to retrieve values from any row on the datagrid where a
user clicked?

Datagrid Values

Please advise how to get data value from specific cell in datagrid. My
datagrid is connected to ADO through custom class; it retrieves data
correctly and coherently from database, but I cannot seem to figure out a
way to get a value from a user updated cell back to database - nay, I can't
even get a value from cell to display in msgbox, just plain can't seem to
get updated cell value at all. Thanks in advance.

Ralph D. Lynch
ITS Corporation

Datagrid Add Values
hallow all

i'm using a datagrid to show values you can add with my program.
i'm not using a database.

is it posible to wread and write data into tha grid without connecting a

anad if this is posible, how ???

i just can't find useful information n the internet for my problem

thanks Maarten

How Do I Show Only One Customers Record On A Datagrid Locked To Dataenvironment
I have 2 datagrids on one form, one parent showing Customer's name & address, the other is a child of that table showing items ordered.
How do I make the datagrids show only the data from one customer selected in a combo from a list of customers?
When I try to put a reference to the combo box in the SQL statement for the dataenvironment source, I get an error.
Is there maybe a filter I can add somewhere?

Getting Datagrid Values Into An Array?
I have a datagrid that has the results of a query i made to my database. The function of my sql query was to return all the values in my" exam_order" field that are greater than 0. So i have 130 records sitting in my datagrid. What i want to do is put all those records into an array. Not sure how to do this.

How To Print DataGrid Values?
In VB.NET there is this PrintDocument control that will do the job, but unfortunately I am using Visual BAsic 6.0 Anyone know the vb code to print datagrid values by not using shareware .dll to do that? (cos I can't register .dll in school

Boolean Values In Datagrid
I am having trouble displaying boolean values in a bound datagrid control. I want to display the value as a checkbox, but I can only get it to show as a 0 or -1. I have tried the format tab on the Datagrid property form and that doesn't seem to do anything. I have also tried setting the format in code using the DataFormat proprty but get a runtime error saying the property is not supported.
When I view the data in Access it automatically shows as a checkbox. How can I do this in my own application?

Datagrid Values To Textbox
Hi all,

I am very new to VB. I am using VS2005 vb. I have two textboxes and one grid with two columns

I want to populate the grid values to text box while clicking the exact row?

Is it possible?

can any one give me the solution..?


How To Add The Recordset Values In DATAGRID
Hey to all..

I am new to VB. i am having some of the values in recordset which has mutliple fields. how to show the data in Datagrid. Can anyone guide me what coding i have to implement.

How To Enter Values By Using DataGrid
hi there all...

i want to enter data by using the datagrid

how i can do this


Adding Values From A Datagrid
Hi all,
Quick question. I want to add numberical values from the same column of a datagrid and post the sum into a text box. So basically i just want to get the sum of a particular column. what would be the trick to this?

Adding Values To DataGrid
How can we add values DataGrid's Rows and Columns

Thanks in advance

Values Are Not Populating In The Datagrid
values are not populating in the datagrid ...?

How To Calculate Values In A Datagrid.
I`am entering values in a datagrid.

How can i calculate all the values of prices of items added to the datagrid, to show me the sum of all the items prices added together.  

Copyright © 2005-08, All rights reserved