views:

314

answers:

1

I have added checkboxes into a DataGird, but they are not enabling they just disable when i click on another control giving you complete source code.

public partial class WinSubnetRangeInput : RibbonWindow
{
    public DataTable objdtIPrange = new DataTable();       

    public WinSubnetRangeInput()
    {
       this.InitializeComponent();

       objdtIPrange.Columns.AddRange(new DataColumn[] { new DataColumn(" ",typeof(Boolean)), new DataColumn("Start IP"), new DataColumn("End IP") });
       dataGridIPs.CanUserDeleteRows = true;           
       //dataGridIPs.ColumnWidth = 264.5;
       if (File.Exists(@"DiscoveryConfig.bin"))
       {
           FileStream fs = null;
           BinaryFormatter bf = null;
           try
           {
               fs = new FileStream(@"DiscoveryConfig.bin", FileMode.Open);
               bf = new BinaryFormatter();
               objdtIPrange = (DataTable)bf.Deserialize(fs);
               dataGridIPs.DataContext = objdtIPrange;
           }
           catch (Exception ex)
           {
               fs.Close();
               File.Delete(@"DiscoveryConfig.bin");  
               MessageBox.Show("Configration file corrupted, Input IP range again.", "VDIworks - Protocol Inspector", MessageBoxButton.OK, MessageBoxImage.Error);
               Thread.Sleep(1000);
           }
       }
       //else
       //{
       //    dataGridIPs.DataContext = objdtIPrange;
       //}
 }

 private void btnAdd_Click(object sender, System.Windows.RoutedEventArgs e)
 {
        IPAddress ipAddress = null;

// if (IPAddress.TryParse(txtFromIP.Text.Trim(), out ipAddress) && IPAddress.TryParse(txtToIp.Text.Trim(), out ipAddress) && !txtToIp.Text.Equals(txtFromIP.Text)) if (IPAddress.TryParse(txtFromIP.Text.Trim(), out ipAddress) && IPAddress.TryParse(txtToIp.Text.Trim(), out ipAddress)) { if(IPCompare.IsGreater(txtFromIP.Text.Trim(),txtToIp.Text.Trim())) { MessageBox.Show("Starting IP should be smaller than ending IP", "VDIworks - Protocol Inspector", MessageBoxButton.OK, MessageBoxImage.Error); return; }

            objdtIPrange.Rows.Add(true, txtFromIP.Text, txtToIp.Text);

            dataGridIPs.DataContext = objdtIPrange;
        }
        else
        {
            MessageBox.Show("Invalid IP Range Specified", "VDIworks - Protocol Inspector", MessageBoxButton.OK, MessageBoxImage.Error);

        }

 }

 private void btnSave_Click(object sender, System.Windows.RoutedEventArgs e)
 {
        FileStream fs = new FileStream(@"DiscoveryConfig.bin", FileMode.Create);
        BinaryFormatter bf = new BinaryFormatter();
        bf.Serialize(fs,objdtIPrange);
        fs.Close();

        //object[] test = null; 
        //test = objdtIPrange.Rows[0].ItemArray;
        //MessageBox.Show(test);
        this.Window.Close();
 }

    private void RibbonCommand_Executed_btnAdd(object sender, ExecutedRoutedEventArgs e)
    {

    }

    private void RibbonCommand_Executed_btnSave(object sender, ExecutedRoutedEventArgs e)
    {

    }

    private void RibbonCommand_Executed_AppMnu(object sender, ExecutedRoutedEventArgs e)
    {

    }

    private void btnCancel_Click(object sender, RoutedEventArgs e)
    {
        this.Window.Close();
        //ProtocolConfiguration.ConfigureProtocols().Rows[2].ItemArray[0].ToString();
    }
}

}

<r:RibbonWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Custom="http://schemas.microsoft.com/wpf/2008/toolkit"
x:Class="VDIUtilities.WinSubnetRangeInput"
x:Name="Window"
Title="Input Subnet Range"  Width="635" Height="280" mc:Ignorable="d" Background="#FFCADAED">

    </ResourceDictionary>
</r:RibbonWindow.Resources>


-->

<Grid x:Name="LayoutRoot" Background="White" VerticalAlignment="Top" Height="171" >
    <Label HorizontalAlignment="Left" Margin="38.5,20.5,0,0" VerticalAlignment="Top" Width="57" Height="30" Content="Start IP:"/>
    <Label Margin="287.5,20.5,295.5,0" VerticalAlignment="Top" Height="30" Content="End IP:" RenderTransformOrigin="0,0.533"/>
    <TextBox x:Name="txtFromIP" HorizontalAlignment="Left" Margin="105.5,25,0,0" VerticalAlignment="Top" Width="166" Height="21" Text="" TextWrapping="Wrap"/>
    <TextBox x:Name="txtToIp" Margin="0,25,118.5,0" VerticalAlignment="Top" Height="21" Text="" TextWrapping="Wrap" HorizontalAlignment="Right" Width="166" d:LayoutOverrides="HorizontalAlignment, Width"/>
    <Button x:Name="btnAdd" HorizontalAlignment="Right" Margin="0,25,51.5,0" VerticalAlignment="Top" Width="52" Height="21" Content="Add" Click="btnAdd_Click"/>
    <Custom:DataGrid x:Name="dataGridIPs" Margin="38.5,75,51.5,26" AlternationCount="2"  AutoGenerateColumns="True" ItemsSource="{Binding}" AlternatingRowBackground="#FFCDE1FC" BorderBrush="Black" RowBackground="#FFD8E8FC" d:LayoutOverrides="VerticalAlignment" Height="66"/>


    <Button x:Name="btnSave" Margin="249,0,0,1" VerticalAlignment="Bottom" Height="21" Content="Save" Click="btnSave_Click" d:LayoutOverrides="VerticalAlignment" HorizontalAlignment="Left" Width="47"/>
 <Button x:Name="btnCancel" Margin="310,0,270,1" VerticalAlignment="Bottom" Height="21" Content="Cancel" Click="btnCancel_Click" d:LayoutOverrides="VerticalAlignment"/>
</Grid>
</DockPanel>

A: 

It is a BUG IN MICROSOFT COMPONENT DON'T WORRY IT IS USUAL ... HOW COULD YOU IDENTIFY IT THAT IT IS FROM MICROSOFT IF IT IS BUG FREE :)) WELL JUST A JOKE REMOVE '/' FROM COLUMN NAME AND EVERY THING WILL LOOK LOVABLE AGAIN

Aizaz