Datagrid customization

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have a datagrid with about 5 columns. It's datasource is a dataset that
also contains a 'comments' field, but I'm not displaying it, as it would take
up too much space.
What I would like to have, is a small 'button' in each row, that displays if
a comment exists for that record, but doesn't if there is no comment.
If a comment exists, the user can click the 'button' to open the comments in
a small form.
Is this possible?
Thanks in advance!
Amber
 
Sure thing. It's a little tricky the first time you do it. But once you do
it a few times it becomes quite easy.

Step 1: Add a column to your query that is TRUE or FALSE based on whether
there are comments or not. Let's pretend you called it "HasComments". You
may need to fiddle with the data type... I haven't explictly done this with
visibility. I think you could just do 1 for true and 0 for false. You might
have to do "TRUE" or "FALSE" as a string.

Step 2: In the Property Builder for the DataGrid, make a template column
that will be used for your button, call it whatever (I'll call it
ButtonColumn).

Step 3: Right click on the grid and choose "Edit Template". You can then
draw your button in that template.

Step 4: Click on the button you've created and find the DataBindings
property. Visible will be there. Select Visible and then select the "Custom
Binding Expression" radio button. In that field put:
DataBinder.Eval(Container, "DataItem.HasComments")
Where HasComments is the name of the field you want to bind to the
visibility property.

Step 5: In the DataGrid_ItemCommand event, build the code to display the
field. I can expand on this if you get this far and can't figure it out, but
I'm late for a meeting, hehe.

Good luck
 
Gah, I'm so ticked up. I wrote up a throrough explanation of how to do it
and this dang thing ate my post.

In a nutshell - make the column for the button a template column and bind
the visibility property of that button to a field that is TRUE or FALSE on
the returned recordset. Then write code in the DataGrid_ItemCommand event to
display the comment.

Man, that stunk. Sorry, but I"m not retyping the whole explanation.
 
Thanks for your help Shawn.
Where do I find Property Builder for a datagrid?
I did a search, and I keep reading 'right clickon datagrid and select
property builder'.
When I right-click my datagrid, I don't have this option...

TIA,
Amber
 
Back
Top