1

我有两个 dxg:GridControl 控件。一个控件具有复选框列,当用户想要从第一个 dxg:GridControl 中选择一条记录时,用户将单击该记录上的复选框,这样用户将能够选择多条记录。当用户单击 BtnGetSelected_Click 按钮时,我想获取所有选定的数据并显示在第二个 dxg:GridControl 中,而无需从第一个 dxg:GridControl 中删除记录。

Can someone please help me to do this.

My second goal is to enhance this program to drag and drop record from first dxg:GridControl to second dxg:GridControl. 

Much appreciate someone hep me to achieve these two.

I have been searching for an answer for more than 4 days now.

Thank you very much.

My code is as follows 

<dxlc:LayoutControl>
<Button Click="BtnInvert_Click">Invert selection</Button> 
<Button Click="BtnGetSelected_Click" Width="100" Height="100">Get selection</Button>
<dxg:GridControl AutoPopulateColumns="True" AllowDrop="True"  Name="Examinersdata" MouseLeftButtonDown="tableview_MouseLeftButtonDown_1" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" DragOver="Examinersdata_DragOver_1" DragLeave="Examinersdata_DragLeave_1" Drop="Examinersdata_Drop_1" Width="500" CustomUnboundColumnData="grid_CustomUnboundColumnData">
<dxg:GridControl.Columns>
                <dxg:GridColumn FieldName="id" />
                <dxg:GridColumn FieldName="LastName" />
                <dxg:GridColumn FieldName="FirstName" />
                <dxg:GridColumn FieldName="Country" />                  
                <dxg:GridColumn FieldName="State" />
                <dxg:GridColumn FieldName="Written" />
                <dxg:GridColumn FieldName="Clinical" />
                <dxg:GridColumn FieldName="ObserverOrSupervisor" />
                <dxg:GridColumn FieldName="Selected" UnboundType="Boolean" AllowSorting="False">
                    <dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <dxe:CheckEdit x:Name="PART_Editor"/>
                            </DataTemplate>
                        </dxg:GridColumn.CellTemplate>
                    </dxg:GridColumn>
                </dxg:GridControl.Columns>
            <dxg:GridControl.View > 
            <dxg:TableView Name="tableview" MultiSelectMode="None"  ShowGroupedColumns="True" EditorShowMode="MouseUpFocused" >
</dxg:TableView>
</dxg:GridControl.View>
<i:Interaction.Behaviors>
<dxg:GridDragDropManager x:Name="gridDragDropManager" AllowDrag="True" AllowDrop="True">
                        <dxg:GridDragDropManager.TemplatesContainer>
                        <dxg:DragDropTemplatesContainer/>
                    </dxg:GridDragDropManager.TemplatesContainer>
                    </dxg:GridDragDropManager>
</i:Interaction.Behaviors>
</dxg:GridControl>
<dxg:GridControl AutoPopulateColumns="True" AllowDrop="True" Name="Examinersdata1" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" DragOver="Examinersdata_DragOver_1" DragLeave="Examinersdata_DragLeave_1"   >
                <dxg:GridControl.View>
                    <dxg:TableView ShowTotalSummary="False"/>
                </dxg:GridControl.View>
<i:Interaction.Behaviors>
                    <dxg:GridDragDropManager x:Name="gridDragDropManager1" AllowDrag="True" AllowDrop="True"  Drop="DropManager_Drop">
                        <dxg:GridDragDropManager.TemplatesContainer>
                            <dxg:DragDropTemplatesContainer/>
                        </dxg:GridDragDropManager.TemplatesContainer>
                    </dxg:GridDragDropManager>
                </i:Interaction.Behaviors>
            </dxg:GridControl>  
</dxlc:LayoutControl>
</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;
using Microsoft.SharePoint.Client;
using System.Threading;
using Microsoft.SharePoint;
using System.Windows.Data;
using System.Linq;
using System.Collections.ObjectModel;
using DevExpress.Xpf.Grid;
namespace SilverlightProject1
{
    public partial class MainPage : UserControl
    {
        Dictionary<Guid, bool> selectedValues = new Dictionary<Guid, bool>();
        List<TestData> list;

        public string childId_Value;
        public string childId_Value1;
        public string writtenok;
        public string clinicalok;
        public string ObserverOrSupervisorOk;
        public string strSelectedTab;
        public string x;
       public GridViewHitInfoBase downHitInfo = null;



        private ListItemCollection _exmDetails;

        public ClientContext context;
        public List exmDetails;

        public class Examiners
        {
            public int id { get; set; }
            public String LastName { get; set; }
            public String FirstName { get; set; }
            public String Country { get; set; }
            public String State { get; set; }
            public String Written { get; set; }
            public String Clinical { get; set; }
            public String ObserverOrSupervisor { get; set; }

        }
        public class TestData
        {
            public Guid Id { get; set; }
            public int Number { get; set; }
        }

        public MainPage()
        {
            InitializeComponent();
            GetalldatafromExaminersList();


        }




        public void GetalldatafromExaminersList()
        {

            context = ClientContext.Current;
            context.Load(context.Web);
            exmDetails = context.Web.Lists.GetByTitle("ExaminersList");
            context.Load(exmDetails);

            CamlQuery query = new Microsoft.SharePoint.Client.CamlQuery();


            _exmDetails = exmDetails.GetItems(query);
            context.Load(_exmDetails);
            context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), null);
        }


        private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
        {
            // This is not called on the UI thread.
            Dispatcher.BeginInvoke(BindData);
        }

        private void BindData()
        {

           List<Examiners> Examiner = new List<Examiners>();
            foreach (ListItem li in _exmDetails)
            {
                var childIdField = li["Country"] as FieldLookupValue;
                if (childIdField != null)
                {
                    childId_Value = childIdField.LookupValue;
                    var childId_Id = childIdField.LookupId;
                }

                var childIdField1 = li["State"] as FieldLookupValue;
                if (childIdField1 != null)
                {
                    childId_Value1 = childIdField1.LookupValue;
                    var childId_Id1 = childIdField1.LookupId;
                }

                if (li["Written"].ToString() == "True")
                    writtenok = "yes";
                else writtenok = "No";

                if (li["Clinical"].ToString() == "True")
                    clinicalok = "Yes";
                else clinicalok = "No";

                if (li["Observer_x0020_Or_x0020_Supervis"].ToString() == "True")
                    ObserverOrSupervisorOk = "Yes";
                else ObserverOrSupervisorOk = "No";


                Examiner.Add(new Examiners()
                {
                    id =Convert.ToInt32(li["ID"]),
                    LastName = li["Title"].ToString(),
                    FirstName = li["First_x0020_Name"].ToString(),
                    Country = childId_Value,
                    State = childId_Value1,
                    Written = writtenok,
                    Clinical = clinicalok,
                    ObserverOrSupervisor = ObserverOrSupervisorOk,

                });




            }


            Examinersdata.ItemsSource = Examiner;

        }


private void DropManager_Drop(object sender, DevExpress.Xpf.Grid.DragDrop.GridDropEventArgs e)
        {


            if (e.DraggedRows != null)
            {

                Examinersdata1.ItemsSource = e.DraggedRows;



            }
        }

        private void grid_CustomUnboundColumnData(object sender, GridColumnDataEventArgs e)
        {
            if (e.Column.FieldName == "Selected")
            {

                int d;
                int y = e.ListSourceRowIndex;
                d = y + 1;
                Guid key = ToGuid(d);
                if (e.IsGetData)
                {
                    e.Value = GetIsSelected(key);
                }
                if (e.IsSetData)
                {
                    SetIsSelected(key, (bool)e.Value);
                }
            }

        }
        public static Guid ToGuid(int value)
        {
            byte[] bytes = new byte[16];
            BitConverter.GetBytes(value).CopyTo(bytes, 0);
            return new Guid(bytes);
        } 

        bool GetIsSelected(Guid key)
        {
            bool isSelected;
            if (selectedValues.TryGetValue(key, out isSelected))
                return isSelected;
            return false;
        }
        void SetIsSelected(Guid key, bool value)
        {
            if (value)
                selectedValues[key] = value;
            else
                selectedValues.Remove(key);
        }
        private void BtnInvert_Click(object sender, RoutedEventArgs e)
        {


        }

        private void BtnGetSelected_Click(object sender, RoutedEventArgs e)
        {
            string selectedIds = string.Empty;
            foreach (Guid key in selectedValues.Keys)
            {
                selectedIds += string.Format("{0}\n", key);
            }
            string caption = string.Format("Selected rows (Total: {0})", selectedValues.Count);
            MessageBox.Show(selectedIds, caption, MessageBoxButton.OK);


        }


    }
}
4

0 回答 0