Datagrid nightmare!!!

U

ufgator1978

Hi All,

I am in some desperate need of help and guidance as I am kind of lost
on this issue. I am using a datagrid for the first time, so please
bare with me. I am trying to make a 8 row by 5 column table, with
column 1 being a text column and 2-5 as a checkbox column.
Additionally, I need to have the ability to
enable/un-enable the checkboxes. Lastly, not every cell in columns 2-5
will have a checkbox in it so I need to be able to skip certain cells
or I need to be able to hide the checkbox in a particular cell. Below
is a quick 'sketch' of what I am trying to do:

|Column1 Column2 Column3 Column4 Column5
|Text [x] [x] [x] [x]
|Text [x] [x]
|Text [x] [x] [x]

....and so on. Can someone PLEASE help? I am stuck and am not sure how
to do this. Thank you so much for your time and effort!!!
 
C

Chris

Hi All,

I am in some desperate need of help and guidance as I am kind of lost
on this issue. I am using a datagrid for the first time, so please
bare with me. I am trying to make a 8 row by 5 column table, with
column 1 being a text column and 2-5 as a checkbox column.
Additionally, I need to have the ability to
enable/un-enable the checkboxes. Lastly, not every cell in columns 2-5
will have a checkbox in it so I need to be able to skip certain cells
or I need to be able to hide the checkbox in a particular cell. Below
is a quick 'sketch' of what I am trying to do:

|Column1 Column2 Column3 Column4 Column5
|Text [x] [x] [x] [x]
|Text [x] [x]
|Text [x] [x] [x]

...and so on. Can someone PLEASE help? I am stuck and am not sure how
to do this. Thank you so much for your time and effort!!!

How are you determining if the column is to show the check or not?

Is this Windows Forms or Web Forms?

This is going to take a fair amount of overriding of code to do. Does
it have to be a checkbox or could literally a "[X]" in a cell do the trick?

Chris
 
U

ufgator1978

Thanks for your reply Chris,

The visibility of the check box is determined in a different part of
the application which doesn't really have anything to do with the grid
itself, other than the grid needing to know whether to display the
checkbox.

This is a Windows Form and unfortunately I need an actual checkbox, the
"[X]" will not suffice.
 
C

Chris

Thanks for your reply Chris,

The visibility of the check box is determined in a different part of
the application which doesn't really have anything to do with the grid
itself, other than the grid needing to know whether to display the
checkbox.

This is a Windows Form and unfortunately I need an actual checkbox, the
"[X]" will not suffice.

How are you populating the datagrid with data? Are you using a datatable?

How I've done stuff like this is to put an extra column in the datatable
that states the visibility setting. Then you need to override the
DataGridCheckBoxColumn's paint event to handle this. You are basically
going to end up do most of the drawing yourself.

The reason you need the visibility setting in the datasource is because
that is the only way that cell can know it's "state".

There are several ways to override the event, I prefer inheriting the class:

Public Class MyDataGridCheckBoxColumn
inherits DataGridCheckBox (not positive that's the exact name)

public sub OnPaint(....)
Dim DT as DataTable = DirectCast(Me.DataGridTableStyles.DataSource,
DataTable)
Dim Visibility as Boolean
Visibility = CBool(DT.Rows(RowNum)("ColumnName"))
'Now do drawing yourself in the cell.
end Sub
End Class
 
U

ufgator1978

Cor,

The example you provided builds the grid, which I have already been
able to get working. I'm more concerned with the visibility of the
checkboxes....thank you for providing the link though, I hope someone
finds it helpful!

Chris,

Thank you for your detailed input. I am going to attempt to get it
working. I'll post back after I give it a shot!
 
U

ufgator1978

Kerry,

That control looks like it is exactly what I need to do!!!!! Thank you
so much everyone!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top