How To Set Focus To Specific Cell In A Datagrid?
Hello brainy people,
I love this place because there are so many brainier people than me here. I can usually find answers to my insignificant little problems with a simple search. But this time I need to post.
I have a datagrid (datagrid1) on my form which is linked to an ADO recordset (rsProductCosts). To validate the data entered by the client I use the sub Datagrid1_Validate to loop through the recordset and check that each required column has been completed and it's contents confirm to the required datatype. The point at which I am having a problem is passing focus back to the relevant cell of datagrid1 when the data doesn't pass validation. The validate method automatically returns focus to the datagrid but not to the cell which requires action by the client. I have tried the following;
rsProductCosts.AbsolutePosition = currentrow
DataGrid1.col = currentcol
but I can't seem to get it to work. Is it even possible.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Value Of Specific Cell In DataGrid
i am displaying data in a DataGrid. In Click()event i want to get the column(0).value, column(1).value and column(3).value in to variables , of that row. Then i have to open a recordset, these 3 variables as parameters.
Code:Private Sub grdDataGrid_Click()
Dim sCurAccType$, sCurTaxType$, sStatus$
Set rsShowDetails = New ADODB.Recordset
sCurAccType = grdDataGrid.Columns(0).Text 'Account_Type
sCurTaxType = grdDataGrid.Columns(1).Text 'Tax_Type
sStatus = grdDataGrid.Columns(3).Text 'Status
rsShowDetails.Open ("SELECT * FROM tbl_TransDetails WHERE Account_Type = '" & sCurAccType & "'" _
& " AND Tax_Type= '" & sCurTaxType & "'" _
& " AND Status = '" & sStatus & "'" _
& " AND Entry_Date = #" & cmbEntryDate.text & " # " )
I tried with the above code. It is getting values, but with the first row of data. but i want to get values of the row i clicked. Please help me.
Edited by - sreddy on 3/22/2005 8:04:45 AM
Accessing A Specific Cell In A DataGrid?
I have a datagrid hooked up to a MySQL database. I was wondering how I can access a specific row, column, or cell. For example, say I have 3 columns (id, name, and age) and 2 rows. If I wanted to get the name located in Row 2 Column 2, and set the caption of a label in my form to this name in Row 2 Column 2, how do I do it?
How To Set The Value To Specific Cell In DataGrid By Programmin?
I use VB 6 to implement project codes which use Datagrid to present information from database. The Datagrid allows user to modify, delete and add information and under some events I want to set value in specific cell by code such as at cell of first column and third row. How to do it? Thanks!
Insert Information Into A Specific Datagrid Cell
I am using a datagrid connected to an SQL server via an ADO connection.
I need to be able to insert a value into a hidden datagrid field via code. How can I do this?
I am displaying the data in a datagrid. I have set the visibility of the Payrate field to false, for security purposes. Now what I want to happen via code. When the user adds a record to the datagrid they enter the machine number in it's cell. I will use an SQL statment to get the payrate for that particular machine. (I can get this to work). Now for the real problem. How can I set the payrate cell in the added record to the payrate for that machine number.
If this is not clear e-mail me or post any questions you have of me.
If anyone can help with this... I thank YOU.
Datagrid, Cell Lost Focus
I've a datagrid where I can update, but when i update a cell, I want validate that this cell wasn't null. I do this in the datagrid_AfterColUpdate and for the first time it's ok, i see the error messagge perfectly.
If I click in another cell, this messagge doesn't appear anymore.
How can I do for not loose the focus and for each click in another cell i see the messagge until the error be correct?
Thanks for any help.
The code is:
Private Sub dgMensajes_AfterColUpdate(ByVal ColIndex As Integer)
If dgMensajes.Columns(1).Text = "" Then
dgMensajes.Col = ColIndex
ElseIf dgMensajes.Columns(2).Text = "" Then
dgMensajes.Col = ColIndex
Altering A MSFlexgrid Cell Without Cell Getting Focus
I am populating a msflexgrid either from a file or by user input. If the value in any row for column 5 is > 50 and < 200 then the cell backcolor for that cell is red else white.
Doing this is not an issue. The issue lies in that column 5 for any particular row may not get the focus. We have locks on certain columns depending on what is entered in earlier columns.
example: If inputing data and col 1 for a particular row is 1 then allow focus to coloumns 2, 3 and 7 of that row etc.
If input data for col 1 is 2 then allow focus to columns 2, 3 and 5
Problem is that if the user changes the value in column 1 from 2 to 1 and the value in column 5 had been 60 - the cellbackcolor of column 5 for the row is red. Since column 5 can not get the focus now - I can't change the cell back color
Is there anyway of changing a cells backcolor without activating cell enter?
How TAB Key Used In The DataGrid Control For Shifting Cell By Cell
I am using DataGrid Contol in my Application to Enter the data and the DataGrid is associated with the RecordSet of the Adodb and it is directly add and update the data.
Now my Problem is how can i go from on cell to another by pressing TAB key.
-Waiting For your Suggetions.
Focus On A Specific Window
Now I have opened suppose three windows with names win1, win2, win3. Now i want to check whether window win2 is opened or not and if it is opened i want to focus it. Can anyone help me out to do it. I tried as:
But it gives the error 'THIS METHOD OR PROPERTY IS NOT AVAILABLE' or something similar only. what is the proper way to do it. thanx in advance.....
How Do I Get VB To Go To The Last Cell, Not A Specific Cell
sorry guys, im sure this isnt rocket science to you, but this is driving me mad!
The below is a section of code im writing, but the basic principal i am trying to achieve is to go to the bottom of a list of data and then autosum. The thing is i dont want it to use a specific cell, as the amount of data in the column will change.
What am i doing wrong?
ActiveCell.FormulaR1C1 = "=SUM(R[-98]C:R[-1]C)"
Find The Last Cell In A Col With A Specific Value
say I have a list of values in a Column in a worksheet that looks something like:
Does anyone know a quick way to find the ROW NUMBER of the last value that starts 079? Obviously I can loop and stuff, but I was wondering if there was some in-built function that would do this. I have to do this sort of test many times, and looping and testing all the cells seems like a good way to slow this thing to a crawl.
Cheers in advance
Run Macro On Specific Cell Change
Is there a way to have a VB Macro run when a specific cell changes value ? I am able to have a macro run when a "sheet data change" takes place, but do not know how to isolate a specific cell to be watched, while ignoring any other changes to the sheet.
Thanks in advance for any help !!!
Select Specific Cell Range
Microsoft Excel 2003
Microsoft Visual Basic 6.3
I am trying to make my macro select a range of cells whose row numbers are calculated within the macro.
Unfortunately the method I used doesn't seem to work, it tells me there is a 'Run time error 1004' and the debugger goes to the offending line (the second line of code shown below).
I originally recorded the macro, and then edited it to be able to automatically select a different range.
I originally had:
And changed it to:
Range("B[(p + 1) - (r - 1)]:B[p + 1]").select
p & r are both defined beforehand and set equal to numeric values which depend on certain other factors.
This is probably a ridiculous way of going about it and I know very little about programming, but if anyone knows the correct way then I could REALLY use some help.
To Copy Specific Cell From 2 Workbook
I would like to copy specific cell data from 2 workbook to another workbook(which is already existing).I am using VBA for excel. I would like to have the commands button only on the first workbook, without opening the 2nd and 3rd workbook. Can i fetch a cell data from 2nd workbook and write to the 3rd workbook.
Thanks in advance.
** RESOLVED ** Boldface Specific Cell In Flexgrid. Possible ?
Can anyone tell me what combination of .Cell, .Row, .Rowsel, .Colsel I ned to boldface a specific cell i a flexgrid ?
Ideally I would like to boldface specific rows.
I know it can be done, I just haven't hit the right combination yet, and its doing my head in
Problem To See Specific Data In Excel Cell Via VB6
I have a very wierd problem.
I have an Excel file, that looks normaly
I have data in the cells. that I can see while activate the
Excell Program, can manipulate that data... like Cut paste ac..
But when I go into my VB project..
Some of the Cells I see an NULL.. its a problematic subject for me..
I tried it all...can somebody help me????/
This is the code and attach is the Excell file.
The file is Excell2000. Maybe I open the File incorrect in VB..?
Maybe Do you have some triks that I can do?
When I use the Record Count I see all Records.
When I go on F3 some of the Data apears as NULL
(For example : 18112 on its second apearence) even thou I
can see the Data on the excel program.
Thanks in Adnvace
Here is the Code:
Public Function fOpen_ConnDBExcelFrmActive()
'Connect to the Excel DB
'Created by Rinat Sade - iDnext Ltd.
On Error GoTo function_error
Dim objData As New CDBData
Dim pszConnection As String
Dim pszDataBase As String
Set objCn = New ADODB.Connection
If objCn.State = adStateOpen Then
If objRs.status = 1 Then
Set objRs = Nothing
Dim glTheError As Long
'get string connection
'Paste the correct Excel File here !!
pszDataBase = frmActiveForm.txtExcelFile.Text
'glTheError = objData.fGetDBConnection(11, pszDataBase, "")
pszConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & pszDataBase & _
"; Extended Properties=""Excel 8.0;HDR=No;"""
Set objData = Nothing
Dim pszString As String
Set objRs = New ADODB.Recordset
If objRs.State = adStateOpen Then
objRs.CursorType = adOpenStatic
' Use client cursor to allow use of
' AbsolutePosition property.
objRs.CursorLocation = adUseClient
' Open the recordset
pszString = "[" & frmActiveForm.txtTable.Text & "]"
objRs.Open pszString, objCn, adOpenStatic, adLockOptimistic
Debug.Print "Number of Records : "; objRs.RecordCount
Do While Not objRs.EOF
If Len(objRs.Fields("f3").Value & "") <> 0 Then
Debug.Print err.Description, err.Number
How To Search For Data In The Worksheet By Specific Cell Name
First of all, I'd like to apologize if I post this topic in wrong forum. I'm a newbie for VB and now I got one project which has to be implemented in VB.
In my project, I've to write the program to fill in the data in specific cell name in excel spreadsheet. But until now it doesn't work
For example, I've data in range A1:C10 which I've one cell named 'Address', not the value of that cell, which I'd like to fill data in. Firstly, I specified the range in the spreadsheet by using
Set rng = myWorksheet.Range("A1:C10")
then I wanna find where the cell named 'Address' is but I've no idea how to do it. Anybody has and idea? I tried with the command 'Find'
Set rngFound = rng.Find(xxxxxxx, ,yyyyyy , Excel.XlLookAt.xlPart, _
Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, _
but I don't know which parameter I'd pass to this function. Could you pls help me finding out?
Thanks in advance
Which Cell Has Lost Focus
Is there a way i can pick up which cell on a worksheet has been moved off of in the code??
MSHFlexGrid, Focus On A Cell
I have a project with
2 non-modal forms.
1 form is a control panel another contains MSHFlexGrids (called display).
The user can freely move from one to the other.
My challenge is:
When the focus is on the control panel and the user clicks a grid on the display window, every cell from the cell clicked up to the title bar is higlighted in blue as the focus moves to that window (and grid).
Without going into why this is bad, is there a way to have the focus just go to the cell clicked rather than an array of cells when shifting focus from the control panel to the display window?
For those interested, this is why it's bad.
I have double click events on the grids. When an array of cells is selected the cell at the top of the column has focus, not the one clicked. I understand this easily but my users are not computer savvy. They don't understand that they have to single click the grid to set focus first, and THEN double click the cell. The users are just jumping straight in to the double click on the cell when the other window still has focus. This launches my double click event with the title row selected instead of the cell clicked.
Setting Focus In A Cell
I have a Msflexgrid. I use a textbox to edit data on the grid.
When the user want to edit a CELL: Click the cell and the textbox is displayed on the cell. To save the data ENTER.
My problem is that i need to set the focus at:
1) The same cell or
2) in any cell
Why, because when the user press ENTER, the focus is set on other object.
Focus To A Cell In A SSOleDBGrid
I'm having a minor problem, but it would be a great help to me if it was solved!
I have a form with textboxes and a SSOleDBGrid.
On entering the last textbox i want the focus to move to
the first cell of the SSOleDBGrid.
I've tried many things, but nothing works.
I hoping anyone of you guys can help me out.
P.S. Wish you all a happy new year!
Change Back Color Of A Specific Cell In A Msflexgrid
In a msflexgrid, can I set a cell's back color similarly to the textmatrix property for text? I could use the cellbackcolor property but I want to do it without setting the row and col properties to those of that specific cell, i.e. without changing the current row and col values.
Cell In Focus Can Be Used As An Event Trigger?
I have 2 questions:
1) Why is it the text inside a combobox placed on a worksheet
is gray and pale? and connot be resized or font
2) It it a way in Excel to do something when a cell is in
focus? I want the user to put soemthing in a cell from a list i
will give him, to prevent typo. Then i will replace it in the
cell. The list (can be a combo box in a form), will be
generating every time the user cliked a specific cell in the
Thanks for any help.
Copying A Cell From A Datagrid To Another Datagrid
My question is how to copy a datagrid cell to another datagrid cell?
for example; datagrid1 column 1, row 1 to datagrid2 column 2, row 3
DataGrid1.Columns(1).CellValue(DataGrid1.RowBookmark(1)) to capture the value, but I don't know the expression how to copy to datagrid2
Conditional Formatting In Excel Based On Specific Cell Updates
I am creating an excel spreadsheet to track work progress and am having difficulty in setting up some conditional formatting on a column.
I have a header column as below:
Owner Coded Reviewer Review Number Status
Now underneath each of the above column headers, the data entered in each of the cells has an effect on what happens in the status column.
The status column has the following formaul entered in each cell:
=IF(J4<>"",IF(K4>=1,IF(M4<>"",IF(N4<>"","Ready for Rework (Post Review)","Review in Progress"),"Ready for Review"),"Schedule in Progress"),"Not Started")
Now for each of the 5 states which the formula can set in the status column I want to associate a colour - different to each other.
To do this i have created the following VBA:
Dim s As String
For Each c In Worksheets("Sheet3").Range("O2:O909").Cells
s = c.Value
Select Case s
Case s = "Not Started"
.ColorIndex = 3
.Pattern = xlSolid
Case s = "Schedule in Progress"
.ColorIndex = 38
.Pattern = xlSolid
Case s = "Ready for Review"
.ColorIndex = 36
.Pattern = xlSolid
Case s = "Review in Progress"
.ColorIndex = 40
.Pattern = xlSolid
Case s = "Ready for Rework (Post Review)"
.ColorIndex = 46
.Pattern = xlSolid
Case s = "Closed"
.ColorIndex = 35
.Pattern = xlSolid
My spreadsheet has almost 1000 rows and hence I do not want this to check every row when called.
What I want is for when the Owner, Coded, Reviewer, Review Number, or Status cells are updated for a particular row, then the above procedure UpdateStatusColumn2 is ran only on the same row for the cell in the Status column.
How do I do this? I know the for loop a the start will require updating as it will now no be required, but how do I get VBA to run the procedure only a single row when a cell underneath Owner, Coded, Reviewer, or Review Number is modified?
I should also say that I tried to use the Conditional Formatting within the Format menu but it only lets me use 3 conditions - which is not enough
I would appreciate all help offered.
VB6, Entering Data Into MS Access DB, But Into A Specific Cell. Include Screenshots
Hi, my problem is that im making an application similar to a hotel management system(ive already seen source code of others on the net) but for a hospital.
If cmdOCCL1.Caption = "Occupy" Then
Set rs = Con.Execute("Insert into Ward1(RoomNo, FullName) " & _
"Values('" & 1 & "','" & txtPName1 & "')")
with this code its entering into the database table the room no which is 1 and the patients name from the txtbox.
But what i want to do is have the numbers already in the database say 1 - 20.
but the command button must add that name specifically into the row with room no. 1.
so i cant figure how to specifically add data to a specific row or cell type thing.
because say i do room 1 and the patients name goes next to room 1, then i do room 7 it will just stack one after another putting the patients name from room 7 next to room 2.
so names just stack or go in one after another.
so i'd like to figure how to put it in the specific cell or row and also how to have max room no's or rows kept at 20.
thx all help appreciated.
Focus Entire Row NOT SINGLE CELL In Mshflexgrid Control
Hi Guyz, m back. this is my code...
TmpRow = 0
i = recset!emp_id
For j = 1 To emplistgrid.Rows - 1
emplistgrid.Row = j
If i = emplistgrid.TextMatrix(emplistgrid.Row, 0) Then
TmpRow = emplistgrid.Row
emplistgrid.Row = 0
emplistgrid.Col = 0
If TmpRow > 0 Then
emplistgrid.Row = TmpRow
emplistgrid.Col = 2
emplistgrid.TopRow = TmpRow
Yeah, I can give focus to mshflexgrid with the record that im pertaining to but it just gave me a SINGLE CELL focusing, pls. help me do how to focus that certain record with ENTIRE ROW.
thanks in advance...
Selecting Specific Row From The Datagrid
i am using datagrid in my program to show all the record in the database
i am not being able to find the way that i click on one row and the record on that row come in the textboxes
tell me the easiest way and with simple example
Refresh DATAGRID (SPECIFIC)
Hi!! i try to refresh the datagrid where my data from database are!! i need to refresh only that record where i made the changes, not all datagrid, becouse then the ACTIVE record again is first, but i need that the Active record is the same after refreshing datagrid!!
Search Datagrid For Specific String
I use Visual Basic Version 6, SP5.
I have a Datagrid that I use dynamically, the values will not reflect the database. I do need to search for either the string, "Pass or Fail", in lower or upper case, in columns 1 through 8, all rows. I looked everywhere on this site and could not find a example.
If the string is found, I just need to copy the information to a text box.
THX in advance.
Adding A Row At A Specific Location In DataGrid
How to add a row at specific location in DataGrid OR FlexGrid Control,
eg. Consider a DataGrid OR FlexFrid control with 10 records, i want to add a row after 5th record.
How this can be done ?????????
Printing Specific Rows In A Datagrid
Im trying to print rows in a datagrid, the code I am using:
Dim varBmk As Variant
For Each varBmk In Grid1.SelBookmarks
Grid1.Row = varBmk - 1
Grid1.Col = 0
strTemp = (Grid1)
PrintTextOnPrinter 12, RowNumber, strTemp
Grid1.Col = 1
strTemp = (Grid1)
PrintTextOnPrinter 44, RowNumber, strTemp
Grid1.Col = 2
strTemp = (Grid1)
PrintTextOnPrinter 76, RowNumber, strTemp
The code above works fine but only for yhe first few rows in the datagrid, if I try and print the rows further down the datagrid the bookmark seems to jump to the bottom of the grid and prints the last record instead of the one i clicked on.
Please someone show me where I am going wrong!!
Edited by - Paul_D on 6/30/2004 2:07:23 AM
Populating A Datagrid Relating To A Specific Value
my datagrid is bound to a table called OrderDetails. this table contains the following fields:
OrderNo (PK), ProductCode(also PK), ProductDesc, Quantity, Price.
the datagrid displays all the fields in the table, except order number. Records are added incrementally to the table (hence, also the datagrid) when a button is pressed. however, i want it to display only records relating to a specific OrderNo (ie the value in the textbox txtOrderNo.Text). how would i go about this? i have tried tying it to a SQL statement but i am very unsure of the syntax, as you can see from the following snippet:
tSQL = "Select ProductCode, ProductDesc, Quantity, Price From OrderDetail Where OrderNo = " & iOrderNo & ""
Set RS = Conn.Execute(tSQL)
Set DataGrid2.DataSource = RS
MsgBox ("Adding record to the datagrid")
Thanks in advance!
Datagrid Calculate Value In Specific Column
How can you calculate the total of values from one specific column into a datagrid and return that value into text field automatically?
Here the fact...
I'm using Master/Detail Form..
Master fields are:
Detail fields are:
So, i want to calculate the sum of Time and return the value into Totaltime.
Thanks for help !
Opening Excel, Selecting Book / Sheet - Read/write Data To/from Specific Cell Usinf WIN 3A
Please can someone inform me how to do the following using Win32 API functionds onlyl;
1) open excel
2) open a named bookbook and select specific sheet
3) read or write an entry into or out of a specific cell;
I have opend other programs before from a VB6 environment using shell execute statement, however in this problem I am not using VB6, rather a prorietary programming language that allows me to have access to WIN 32 API functions - so my problem has to be solved using these functions only.
Any one's help on this probelm is greatly appreciated.
How To Set Focus In A Datagrid
I am using VB6. I am using a data grid. Each time a user updates information in the data grid, I requery data and put it the datagrid with the updated information. When a user modifies a record from the datagrid, I can capture the row id. When a user updates the datagrid, the cursor moves to top of the datagrid. I do not want that. I want to move the curser where the data was modified last time. Is there any way to set the focus to a record in a datagrid?
Find And Select A Specific Row In DataGrid Control In VB6.
In code I need to find, select and highlight a specific row in a DataGrid control based on the value of a specific field (column) in the grid. Iterating through the rows using .Row is unacceptable because .Row only deals with visible rows and the row being sought may not be visible. Ideas?