private void columnHeader_Click(object sender, RoutedEventArgs e)
        {
            var columnHeader = sender as DataGridColumnHeader;
            var lll          = columnHeader.DisplayIndex;

            if (columnHeader != null)
            {
                //POINT p = new POINT();

                Point pp  = Mouse.GetPosition(e.Source as FrameworkElement);  //WPF方法
                Point ppp = (e.Source as FrameworkElement).PointToScreen(pp); //WPF方法

                SelectColumn sc = new SelectColumn(tbGLXM.Text, columnHeader.DataContext.ToString());
                sc.WindowStartupLocation = WindowStartupLocation.Manual;
                sc.Left = ppp.X;
                sc.Top  = ppp.Y;
                if (sc.ShowDialog() == true)
                {
                    for (int i = 0; i < DataGrid1.Columns.Count; i++)
                    {
                        DataGridTextColumn dgcol = DataGrid1.Columns[i] as DataGridTextColumn;
                        DataGridColumn     col   = DataGrid1.Columns[i];

                        Binding binding = dgcol.Binding as Binding;
                        string  path    = binding.Path.Path;

                        if (path == columnHeader.DataContext.ToString())
                        {
                            DataGrid1.Columns[i].Header = sc.Name; break;
                        }
                    }
                    //columnHeader.Content = sc.Name;
                }
            }
        }
Ejemplo n.º 2
0
        private void BtnSelect_Click(object sender, RoutedEventArgs e)
        {
            if (ListBox1.SelectedIndex == -1)
            {
                MessageBox.Show("在左边列表中请选择一个字段"); return;
            }
            ListBoxItem  item = (ListBoxItem)ListBox1.SelectedItem;
            SelectColumn win  = new SelectColumn(tableName, item.Tag.ToString());

            if (win.ShowDialog() == true)
            {
                ListBoxItem temp = new ListBoxItem();
                temp.Content = item.Content + " >> " + win.Name;
                temp.Tag     = item.Tag;
                dic.Add(item.Tag.ToString(), win.Name);
                ListBox1.Items.Remove(ListBox1.SelectedItem);
                ListBox2.Items.Add(temp);
            }
        }