Datagrid Questions

  • Thread starter Thread starter Ed Bick
  • Start date Start date
E

Ed Bick

I know how to do this stuff so easily in VB6.........

3 questions.

I have loaded a grid by binding it to a dataset. All is well with that.

1) How do I retrieve the value of a column when a user clicks on a row? I
use a Sheriden grid in VB6 and would do something like:

MyString = MyGrid.Columns(n).Text

2) Some of the columns I'm pulling are datetime columns that have not been
set yet. I am getting (null) in the column. How do I prevent that and just
display nothing?

3) I have a column that is a bit field. Before I applied any formatting,
the column came back as a greyed checkbox. The value at the time was
(null). Now, with formatting and values, I'm getting True or False. I want
a checked or unchecked checkbox. How do I do that?

Thanks in advance.
 
Hi,

1) If you have add a tablestyle to your datagrid
Dim dc As DataGridCell = DataGrid1.CurrentCell

If DataGrid1.TableStyles.Count > 0 Then

MessageBox.Show(DataGrid1.TableStyles(0).GridColumnStyles.Item(dc.ColumnNumber).HeaderText)

End If


2) Add a tablestyle to your datagrid. The datagridtextboxcolumn has
a nulltext property set this to what you want it to display instead of
(null).

3) Set a default value for your datacolumn to prevent the grayed
checkbox.
ds.Tables("Products").Columns("Discontinued").DefaultValue = False



Ken
 
Ken,

Thanks for your help.

on #1, what I am returning with this code is the column header text. I am
looking to get the value on the specific row in the grid.

on #3, I guess I wasn't clear enough. I'm not necessarily aiming at
preventing the greyed checkbox. I want checkboxes. So, if my value coming
back from the DB is a 0, I want an unchecked checkbox. If it's 1, I want a
checked checkbox. I have the grid as ReadOnly, so the greyed or not greyed
part doesn't matter so much.

Thanks in advance, again.
 
That did the trick.

ONE more question, if you don't mind.

So, I've bound my grid to a dataset. Now a user clicks another control and
I want to wipe the grid clear and rebind it to the new dataset. My current
code is appended to the dataset. I can not seem to find the equivalent to
the clear method.
 
Back
Top