Click here to Skip to main content
15,880,503 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Another Silverlight upgrade headache - Hashtable Pin
Mark Salsbery17-Feb-09 15:34
Mark Salsbery17-Feb-09 15:34 
GeneralRe: Another Silverlight upgrade headache - Hashtable Pin
Mark Salsbery17-Feb-09 15:39
Mark Salsbery17-Feb-09 15:39 
GeneralRe: Another Silverlight upgrade headache - Hashtable Pin
devvvy17-Feb-09 22:53
devvvy17-Feb-09 22:53 
GeneralRe: Another Silverlight upgrade headache - Hashtable Pin
Mark Salsbery17-Feb-09 22:55
Mark Salsbery17-Feb-09 22:55 
GeneralRe: Another Silverlight upgrade headache - Hashtable Pin
pieterbosteels17-Feb-09 22:47
pieterbosteels17-Feb-09 22:47 
GeneralRe: Another Silverlight upgrade headache - Hashtable Pin
devvvy17-Feb-09 22:52
devvvy17-Feb-09 22:52 
AnswerRe: Another Silverlight upgrade headache - Hashtable Pin
Braulio Dez12-Mar-09 23:14
Braulio Dez12-Mar-09 23:14 
QuestionProblem with DataGrid (selected rows) Pin
Czechtim216-Feb-09 12:35
Czechtim216-Feb-09 12:35 
I have problem with selected rows in DataGrid from WPF Toolkit. I have Observable Collection as ItemsSource.

I created small sample application. I´m adding file adresses to DataGrid and when I click on row in DataGrid I´m testing existence of file. If file doesn´t exit I remove that selected row automatically from DataGrid (ObservableCollection).

Problem is, that sometimes after deleting a row from DataGrid, previously selected row still remains as selected (blue background of row). But that row isn´t selected, because when I click on buton „Delete selected row“ I recieve message that no row is selected.

Exactly: When I have in DataGrid selected row (x) and a click on row (x + 1) and file doesn´t exit at row (x + 1), that row (x + 1) is automatically deleted and no row is selected - everything´s all right.

But when I have selected row (x) and a click on row (x - 1) and file doesn´t exit at row (x - 1), that row (x - 1) is deleted but row (x) still remains as selected (blue background of row x) - PROBLEM.

Doessomebody know please how to solve it? I need to have all rows visually unselected every time in my application after deleting a row in DataGrid (white background of all rows).

Here´s my code:

Window1.xaml
<Window x:Class="DataGrid.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Grid.RowDefinitions>
             <RowDefinition Height="*" />
             <RowDefinition Height="*" /> 
             <RowDefinition Height="9*" /> 
         </Grid.RowDefinitions>
             <ColumnDefinition Width="*" />
             <ColumnDefinition Width="*" />
        <Grid.ColumnDefinitions>

        </Grid.ColumnDefinitions>

        <dg:DataGrid x:Name="dataGrid" 
                     Grid.Row="3" 
                     Grid.ColumnSpan="2"
                     SelectionChanged="dataGrid_SelectionChanged" 
                     Grid.Column="0" 
                     CanUserDeleteRows="True" 
                     Loaded="dataGrid_Loaded"
                     IsReadOnly="True" 
                     SelectionUnit="FullRow" 
                     SelectionMode="Single" 
                     CanUserAddRows="False" 
                     Visibility="Visible"
                     Margin="1" 
                     Background="White" 
                     AlternationCount="2" />
        <TextBox Name="textBox1" Grid.Row="0" Grid.ColumnSpan="2" />
        <Button Grid.Row="1" Name="Add" Click="Add_Click">Add address to DataGrid</Button>
        <Button Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" Name="Delete" VerticalAlignment="Top" Click="Delete_Click">Delete selected row</Button>
    </Grid>
</Window>


Window1.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Collections.ObjectModel;

namespace DataGrid
{
    public partial class Window1 : Window
    {

        ObservableCollection<files> obs_col;
        public Window1()
        {
            InitializeComponent();
            obs_col = new ObservableCollection<files>();
        }


        private void dataGrid_Loaded(object sender, RoutedEventArgs e)
        {
            dataGrid.ItemsSource = obs_col;
        }


        private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Files selectedFile = (Files)dataGrid.SelectedItem;

            if (selectedFile != null)
            {
                if (!File.Exists(selectedFile.File))
                {
                    obs_col.RemoveAt(obs_col.IndexOf(selectedFile));
                }
            }
        }


        private void Add_Click(object sender, RoutedEventArgs e)
        {
            obs_col.Add(new Files(textBox1.Text));
        }


        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            Files selectedFile = (Files)dataGrid.SelectedItem;

            if (selectedFile != null)
            {
                obs_col.RemoveAt(obs_col.IndexOf(selectedFile));
            }
            else
                MessageBox.Show("No row is selected");
        }
    }
}</files></files>


Files.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataGrid
{
    class Files
    {

        public string File
        {
            get; set;
        }

        public Files(string file)
        {
            this.File = file;
        }

    }
}

Question[Message Deleted] Pin
Prajeesh15-Feb-09 22:26
Prajeesh15-Feb-09 22:26 
AnswerRe: WPF Pin
Pete O'Hanlon15-Feb-09 22:32
mvePete O'Hanlon15-Feb-09 22:32 
Question[Message Deleted] Pin
Prajeesh15-Feb-09 22:38
Prajeesh15-Feb-09 22:38 
AnswerRe: Languages in WPF Pin
Pete O'Hanlon15-Feb-09 23:18
mvePete O'Hanlon15-Feb-09 23:18 
GeneralMessages in limbo Pin
Luc Pattyn16-Feb-09 3:33
sitebuilderLuc Pattyn16-Feb-09 3:33 
GeneralRe: Messages in limbo Pin
Pete O'Hanlon16-Feb-09 5:16
mvePete O'Hanlon16-Feb-09 5:16 
General[Message Deleted] Pin
Mark Salsbery16-Feb-09 7:53
Mark Salsbery16-Feb-09 7:53 
GeneralRe: Messages in limbo Pin
Pete O'Hanlon16-Feb-09 8:24
mvePete O'Hanlon16-Feb-09 8:24 
GeneralRe: [Message Deleted] Pin
Pete O'Hanlon16-Feb-09 8:41
mvePete O'Hanlon16-Feb-09 8:41 
GeneralRe: [Message Deleted] Pin
Mark Salsbery16-Feb-09 9:30
Mark Salsbery16-Feb-09 9:30 
QuestionCan't reference a Silverlight library from say Console/Winform HelloWorld? Pin
devvvy15-Feb-09 22:10
devvvy15-Feb-09 22:10 
AnswerRe: Can't reference a Silverlight library from say Console/Winform HelloWorld? Pin
Mark Salsbery16-Feb-09 5:38
Mark Salsbery16-Feb-09 5:38 
AnswerRe: Can't reference a Silverlight library from say Console/Winform HelloWorld? Pin
Mark Salsbery16-Feb-09 7:50
Mark Salsbery16-Feb-09 7:50 
GeneralRe: Can't reference a Silverlight library from say Console/Winform HelloWorld? Pin
devvvy16-Feb-09 13:45
devvvy16-Feb-09 13:45 
GeneralRe: Can't reference a Silverlight library from say Console/Winform HelloWorld? [modified] Pin
devvvy16-Feb-09 14:20
devvvy16-Feb-09 14:20 
Question[Message Deleted] Pin
tom4_2515-Feb-09 16:48
tom4_2515-Feb-09 16:48 
AnswerRe: code problem Pin
Pete O'Hanlon15-Feb-09 22:28
mvePete O'Hanlon15-Feb-09 22:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.