I have created a windows application that uses a DataGrid to display and update data from two sql server 2000 tables. I use a DataAdapter to select the data and place in a DataSet, then I link the two tables using a DataRelation. I have two questions related to the properties of the DataGrid. First, in the display of the parent table, I have two DataGridBoolColumn columns. I want to set the second check box to be disabled unless the first check box value is False. Is there a way to set this property (I guess it would be ReadOnly) at run-time? Second, how can I change the check box properties so that they don't allow the DataNull value where the box is greyed with a check? I only want to allow True (checked) or False (unchecked). My fields in the sql tables, which translate to the boolean check boxes, are 1 character fields with a Y or N. I do not allow nulls in these fields.
My code is as follows (please note that I have not included datagrid formatting for the second table yet):
strServer = sGetINI(strINI, "TaxRates", "Server", "")
strDatabase = sGetINI(strINI, "TaxRates", "Database", "")
strSqlConn = "persist security info=false;integrated security=sspi;" & _
"database=" & strDatabase & ";server=" & strServer
Dim TSStates As New DataGridTableStyle
TSStates.MappingName = "States"
Dim TCState As New DataGridTextBoxColumn
TCState.MappingName = "state"
TCState.HeaderText = "State"
TSStates.GridColumnStyles.Add(TCState)
Dim TCAccrueST As New DataGridBoolColumn
TCAccrueST.MappingName = "accrue_state"
TCAccrueST.HeaderText = "State Accruals"
TCAccrueST.FalseValue = "N"
TCAccrueST.TrueValue = "Y"
TSStates.GridColumnStyles.Add(TCAccrueST)
Dim TCAccrueC As New DataGridBoolColumn
TCAccrueC.MappingName = "accrue_city"
TCAccrueC.HeaderText = "City Accruals"
TCAccrueC.FalseValue = "N"
TCAccrueC.TrueValue = "Y"
TCAccrueC.ReadOnly = True
TSStates.GridColumnStyles.Add(TCAccrueC)
dgStates.TableStyles.Add(TSStates)
myDataSet = New DataSet
strAccrSQL = "select * from u_tax_accrual_states"
Conn = New SqlConnection(strSqlConn)
DataAdapter = New SqlDataAdapter(strAccrSQL, Conn)
DataAdapter.Fill(myDataSet, "States")
strAccrSQL = "select * from u_taxes_city"
'Conn = New SqlConnection(strSqlConn)
DataAdapter = New SqlDataAdapter(strAccrSQL, Conn)
DataAdapter.Fill(myDataSet, "Cities")
Dim myDataRelation As New DataRelation("Show Cities", myDataSet.Tables("States").Columns("state"), _
myDataSet.Tables("Cities").Columns("state"))
myDataSet.Relations.Add(myDataRelation)
dgStates.DataSource = myDataSet
dgStates.DataMember = "States
My code is as follows (please note that I have not included datagrid formatting for the second table yet):
strServer = sGetINI(strINI, "TaxRates", "Server", "")
strDatabase = sGetINI(strINI, "TaxRates", "Database", "")
strSqlConn = "persist security info=false;integrated security=sspi;" & _
"database=" & strDatabase & ";server=" & strServer
Dim TSStates As New DataGridTableStyle
TSStates.MappingName = "States"
Dim TCState As New DataGridTextBoxColumn
TCState.MappingName = "state"
TCState.HeaderText = "State"
TSStates.GridColumnStyles.Add(TCState)
Dim TCAccrueST As New DataGridBoolColumn
TCAccrueST.MappingName = "accrue_state"
TCAccrueST.HeaderText = "State Accruals"
TCAccrueST.FalseValue = "N"
TCAccrueST.TrueValue = "Y"
TSStates.GridColumnStyles.Add(TCAccrueST)
Dim TCAccrueC As New DataGridBoolColumn
TCAccrueC.MappingName = "accrue_city"
TCAccrueC.HeaderText = "City Accruals"
TCAccrueC.FalseValue = "N"
TCAccrueC.TrueValue = "Y"
TCAccrueC.ReadOnly = True
TSStates.GridColumnStyles.Add(TCAccrueC)
dgStates.TableStyles.Add(TSStates)
myDataSet = New DataSet
strAccrSQL = "select * from u_tax_accrual_states"
Conn = New SqlConnection(strSqlConn)
DataAdapter = New SqlDataAdapter(strAccrSQL, Conn)
DataAdapter.Fill(myDataSet, "States")
strAccrSQL = "select * from u_taxes_city"
'Conn = New SqlConnection(strSqlConn)
DataAdapter = New SqlDataAdapter(strAccrSQL, Conn)
DataAdapter.Fill(myDataSet, "Cities")
Dim myDataRelation As New DataRelation("Show Cities", myDataSet.Tables("States").Columns("state"), _
myDataSet.Tables("Cities").Columns("state"))
myDataSet.Relations.Add(myDataRelation)
dgStates.DataSource = myDataSet
dgStates.DataMember = "States