none
datagrid问题 RRS feed

答案

  • 我做了一下,没有问题!是不是和你的前台代码有关!?

    前台代码:

    <UserControl x:Class="SilverlightApplication3.TestGrid"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d"
      d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
      
      <Grid x:Name="LayoutRoot" Background="White">
        <sdk:DataGrid AutoGenerateColumns="True" Height="300" HorizontalAlignment="Left" SelectionChanged="gridTest_SelectionChanged"
               x:Name="gridTest" VerticalAlignment="Top" Width="400" />
      </Grid>
    </UserControl>
    
    

     

    后台代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    
    namespace SilverlightApplication3
    {
      public partial class TestGrid : UserControl
      {
        public TestGrid()
        {
          InitializeComponent();
          this.Loaded += new RoutedEventHandler(TestGrid_Loaded);
        }
    
        void TestGrid_Loaded(object sender, RoutedEventArgs e)
        {
          this.gridTest.ItemsSource = User.GetUsers();
    
        }
    
        private void gridTest_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
          MessageBox.Show(this.gridTest.SelectedIndex.ToString());
        }
      }// end for class
      public class User
      {
        public string Name { get; set; }
        public int Age { get; set; }
        public static IList<User> GetUsers()
        {
          IList<User> userList = new List<User>();
          userList.Add(new User() {Name="ddd",Age=21 });
          userList.Add(new User() { Name = "dd1", Age = 22 });
          userList.Add(new User() { Name = "dee", Age = 31 });
          return userList;
        }
      }
    }
    
    

     


    努力!完成了js解析器,还差一个svg插件,一个绘图程序,做好自己,呵呵~!
    2011年7月12日 5:59
    版主

全部回复

  • 请问能给出关键代码吗?

    2008年8月25日 16:17
    版主
  • XAML里的:
            <myBig SmileataGrid x:Name="grd_bx" Width="950" Height="150" Canvas.Left="5"  Canvas.Top="40" FontSize="15" SelectionChanged="grd_bx_SelectionChanged"></myBig SmileataGrid>

     

    cs代码:

     

            public ObservableCollection<v_bxd> grd_bxd;

      ---------------------------------------------------------------------------------------------------------------------------     

            public wz_bx(string gs)   页面初始化时的程序:
            {
                InitializeComponent();
                ServiceReference1.ServiceClient sc = new ServiceReference1.ServiceClient();
                sc.Get_bxdCompleted += new EventHandler<ServiceReference1.Get_bxdCompletedEventArgs>(add_grid);
                sc.Get_bxdAsync(gs);
            }


           void add_grid(object sender, ServiceReference1.Get_bxdCompletedEventArgs e)
            {
                grd_bxd = e.Result;
                this.grd_bx.ItemsSource = grd_bxd;
            }

    -------------------------------------------------------------------------------------------------------------------------------------------------

            private void grd_bx_SelectionChanged(object sender, EventArgs e)  选择行变化时触发的事件
            {
                if (this.grd_bx.SelectedIndex >= 0)
                {
                    this.bx73.Text = grd_bxd[grd_bx.SelectedIndex].序号.ToString();
                }
            }

     

    -------------------------------------------------------------------

    好像不管选哪里行都INDEX= -1

    2008年8月26日 6:07
  • 我做了一下,没有问题!是不是和你的前台代码有关!?

    前台代码:

    <UserControl x:Class="SilverlightApplication3.TestGrid"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d"
      d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
      
      <Grid x:Name="LayoutRoot" Background="White">
        <sdk:DataGrid AutoGenerateColumns="True" Height="300" HorizontalAlignment="Left" SelectionChanged="gridTest_SelectionChanged"
               x:Name="gridTest" VerticalAlignment="Top" Width="400" />
      </Grid>
    </UserControl>
    
    

     

    后台代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    
    namespace SilverlightApplication3
    {
      public partial class TestGrid : UserControl
      {
        public TestGrid()
        {
          InitializeComponent();
          this.Loaded += new RoutedEventHandler(TestGrid_Loaded);
        }
    
        void TestGrid_Loaded(object sender, RoutedEventArgs e)
        {
          this.gridTest.ItemsSource = User.GetUsers();
    
        }
    
        private void gridTest_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
          MessageBox.Show(this.gridTest.SelectedIndex.ToString());
        }
      }// end for class
      public class User
      {
        public string Name { get; set; }
        public int Age { get; set; }
        public static IList<User> GetUsers()
        {
          IList<User> userList = new List<User>();
          userList.Add(new User() {Name="ddd",Age=21 });
          userList.Add(new User() { Name = "dd1", Age = 22 });
          userList.Add(new User() { Name = "dee", Age = 31 });
          return userList;
        }
      }
    }
    
    

     


    努力!完成了js解析器,还差一个svg插件,一个绘图程序,做好自己,呵呵~!
    2011年7月12日 5:59
    版主
  • 一直也没有人回复,那我就冒昧把自己胡答案标记正确呢!
    努力!完成了js解析器,还差一个svg插件,一个绘图程序,做好自己,呵呵~!
    2011年7月12日 6:01
    版主