Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid control 1

Status
Not open for further replies.

dakone

Programmer
Jun 23, 2003
28
CA
I have a datagrid with multiple rows and columns.

I want to create a onClick() that will highlight(select) the entire row pertaining to the cell that was clicked on.

Any examples?
 
You can set the MarqueeStyle so only rows are selected

datagrid1.MarqueeStyle=dbgHighlightRow

or, add the current Bookmark to the SelBookmarks collection
 
No luck all I see is a dotted line highlighting around the cell you select. Any other ideas? The microsoft link seemd to lead to alot of .NET applications. I can't seem to find what I want on there.

Thanks
 
Do you want the record to be Selected AND marked no matter where the user clicks, and not allow the user to edit a cell?

Use
datagrid1.MarqueeStyle=dbgHighlightRow

Otherwise:

Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
DataGrid1.SelBookmarks.Add DataGrid1.Bookmark
End Sub
 
YES! Thankyou! This:
Code:
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
   DataGrid1.SelBookmarks.Add DataGrid1.Bookmark
End Sub
Does the trick. Is there anyway to make the whole line turn black? Currently the line highlights black except for the cell you clicked on which turns blue as if you could edit it which I don't want to do.
 
Please ignor that last post. I was a little hastey to reply and figured it out myself.

New ques: I have a select button under the datagrid and I need to get the cell value from the highlighted row under the column "License" using onClick(). Any examples out there?
 

That is because the cell is editable.
Then use the first suggestion I made.
 
>Please ignor that last post.
OK. (Got crossed posted)

> I was a little hastey to reply and figured it out myself
Please post what you did....

New quest: See thread709-604962
 
Your first suggestion only highlighted the cell clicked on with a dotted outline around that cell only not the entire row.

Using your second suggestion, my cells are setup as uneditable so even when the blue highlight shows up you cannot make changes.

Chickens were counted before they hatched with my attempted fix to make the whole row show up black. Though I was in the endzone; no cigar.

Is it possible to use:
Code:
sCellValue = DataGrid1.Columns(Datagrid1.Col).Value
in an onClick() event? The column containing the value I want is on the farleft of my datagrid. Can I use:
Code:
sCellValue = DataGrid1.Columns(Datagrid1.LeftCol).Value
?
 
>Your first suggestion only highlighted the cell clicked on with a dotted outline around that cell only not the entire row.

Then something is wrong here. The whole row should be marked, including the current cell, until you double click on the cell.

sCellValue = DataGrid1.Columns(0).Value

or possibly

sCellValue = Adodc1.Recordset.Collect(0)
 
This one:
Code:
sCellValue = Adodc1.Recordset.Collect(0)
highlights the cell for editing.

This one:
Code:
sCellValue = DataGrid1.Columns(0).Value
highlights the whole cell but unfortunately not the whole row.
This happens with a single click.
 
>but unfortunately not the whole row

Sorry if that was mis-understood - my fault
My last post was answering TWO questions from your last post.

The
sCellValue = Adodc1.Recordset.Collect(0)
was in response to your question:

>"Is it possible to use:"


And this:
datagrid1.MarqueeStyle=dbgHighlightRow
Should mark the whole row.



 
Not sure I understand how this:
Code:
sCellValue = Adodc1.Recordset.Collect(0)
will select the value of the cell in the selected row in the first column? I need to grab that value and set it to a variable so I can pass it to another frm. I'm feeling a little disorientated. Appreciate the help.
 

I offered you two ways to do this in a previous post.

The data grid is bound to a recordset, so the value in the first column will be the value in the first field of the recordset, unless an edit on that cell, in that record, is in progress. Then the value of the cell will reflect a user change and the recordset will reflect the original value, until the user or code moves to a new record.

Every thing you do to the recordset which the grid is bound to, whether moving, filtering, sorting, editing, deleting, etc, will be reflected immediately in the grid.

 
You'll have to forgive me, I haven't finished my first coffee this morning! Slugs are passing my brainwaves. I've used your suggestions and everthing is great. Your posts are excellent and work 100%. Thanks so much for your patience and help. It is much appreciated. Sorry I took so long to grasp the concept I can see how it may become frustrating. Thanks again.
 

> I haven't finished my first coffee this morning! Slugs are passing my brainwaves

Well, my morning is gone, and so is the coffee, and now it's quiting time - and It's Friday! - so I guess I have a little advantage there....[smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top