I have a ListView
where each item populates my Datagrid
with its respective table from my database. The SQLCommand
is returning and ID, Title, and Inactive column where my the dataType for my Inactive column is a bit
, so it is showing in the DataGrid as a
CheckBox`
The problem I am having is the user is able to make changes to the Title column and it saves fine. However, if the Inactive is checked, it will not save. Also, if a new row is entered, the Checkbox
in the Inactive column will not be enabled
and cannot be clicked.
I am using SQLDataAdapter
to allow the user to make changes in the Datagrid
and save those changes with a button_click
Here is the code for one of my ListView
items:
namespace CaseManagementSystem
{
/// <summary>
/// Interaction logic for TableManagement.xaml
/// </summary>
public partial class TableManagement : UserControl
{
SqlCommand sCommand;
SqlDataAdapter sAdapter;
SqlCommandBuilder sBuilder;
DataSet sDs;
DataTable sTable;
public object MessageBoxButtons { get; private set; }
public object DialogResult { get; private set; }
public TableManagement()
{
InitializeComponent();
}
private void CustomerContact_Selected(object sender, RoutedEventArgs e)
{
try
{
string connectionString = ("Data Source=WINDOWS-B1AT5HC\\SQLEXPRESS;Initial Catalog=CustomerRelations;Integrated Security=True;");
string sql = "SELECT * FROM [hb_CustCntct]";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
sCommand = new SqlCommand(sql, connection);
sAdapter = new SqlDataAdapter(sCommand);
sBuilder = new SqlCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "hb_CustCntct");
sTable = sDs.Tables["hb_CustCntct"];
connection.Close();
dt_TableManagement.DataContext = sDs.Tables["hb_CustCntct"];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Here is where changes are saved:
private void butn_SaveChanges_Click(object sender, RoutedEventArgs e)
{
sAdapter.Update(sTable);
}
Here is my XAML code:
<!--Grid 1-->
<Grid x:Name="Grid1" Grid.Row="2" Grid.Column="0" Margin="15">
<ListView>
<ListViewItem x:Name="CustomerContact" Content="Customer Contact" Selected="CustomerContact_Selected"/>
<ListViewItem x:Name="CsrNames" Content="Customer Service Representative Names" Selected="CsrNames_Selected"/>
<ListViewItem x:Name="DisputeClassification" Content="Dispute Classification" Selected="DisputeClassification_Selected"/>
<ListViewItem x:Name="FinancialAdjustment" Content="Financial Adjustment" Selected="FinancialAdjustment_Selected"/>
<ListViewItem x:Name="InitialCallAnalysis" Content="Initial Call Analysis" Selected="InitialCallAnalysis_Selected"/>
<ListViewItem x:Name="InitialCallReason" Content="Initial Call Reason" Selected="InitialCallReason_Selected"/>
<ListViewItem x:Name="MeterIssue" Content="Meter Issue" Selected="MeterIssue_Selected"/>
<ListViewItem x:Name="OpenInError" Content="Open In Error" Selected="OpenInError_Selected"/>
<ListViewItem x:Name="PrimaryCause" Content="Primary Cause" Selected="PrimaryCause_Selected"/>
<ListViewItem x:Name="RequestedWork" Content="Requested Work" Selected="RequestedWork_Selected"/>
<ListViewItem x:Name="RevenueClass" Content="Revenue Class" Selected="RevenueClass_Selected"/>
<ListViewItem x:Name="ServiceOrderDetails" Content="Service Order Details" Selected="ServiceOrderDetails_Selected"/>
<ListViewItem x:Name="ServiceOrderType" Content="Service Order Type" Selected="ServiceOrderType_Selected"/>
<ListViewItem x:Name="ServiceOrderAdjustment" Content="Service Order Adjusted" Selected="ServiceOrderAdjustment_Selected"/>
<ListViewItem x:Name="UnderlyingCause" Content="Underlying Cause" Selected="UnderlyingCause_Selected"/>
<ListViewItem x:Name="UtilityReportType" Content="Utility Report Type" Selected="UtilityReportType_Selected"/>
<ListViewItem x:Name="WFMIssuedBy" Content="WFM Issued By" Selected="WFMIssuedBy_Selected"/>
</ListView>
</Grid>
<!--Grid 2-->
<Grid x:Name="Grid2" Grid.Row="1" Grid.Column="2" Margin="15">
<DataGrid x:Name="dt_TableManagement"
materialDesign:ListBoxAssist.IsToggle="True"
AutoGeneratingColumn="dt_TableManagement_AutoGeneratingColumn"
Background="White"
IsReadOnly="False"
IsEnabled="True"
ItemsSource="{Binding}"/>
</Grid>
Aucun commentaire:
Enregistrer un commentaire