心理讲师 發表於 2019-10-10 11:22:00

(八十二)c#Winform自定义控件-穿梭框-HZHControls

<h1>官网</h1>
<p>https://www.hzhcontrols.cn</p>
<h1>前提</h1>
<p>入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。</p>
<p>GitHub:https://github.com/kwwwvagaa/NetWinformControl</p>
<p>码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git</p>
<p>如果觉得写的还行,请点个 star 支持一下吧</p>
<p>欢迎前来交流探讨: 企鹅群568015492&nbsp;<img src="https://pub.idqqimg.com/wpa/images/group.png"></p>
<p>来都来了,点个<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 18pt; color: rgba(255, 0, 0, 1)"><strong>【推荐】</strong></span>再走吧,谢谢</p>
<h1>NuGet</h1>
<div class="cnblogs_code">
<pre>Install-Package HZH_Controls</pre>
</div>
<h1>目录</h1>
<p>https://www.cnblogs.com/bfyx/p/11364884.html</p>
<h1>用处及效果</h1>
<p><img src="https://img2018.cnblogs.com/blog/396919/201910/396919-20191010111904349-470571054.gif"></p>
<h1>准备工作</h1>
<p>这个用到了(一)c#Winform自定义控件-基类控件、(三)c#Winform自定义控件-有图标的按钮&nbsp;、&nbsp;(三十二)c#Winform自定义控件-表格&nbsp; 不了解的可以先移步查看一下</p>
<h1>开始</h1>
<p>添加一个用户控件UCTestTransfer</p>
<p>界面放2个表格,2个按钮即可</p>
<p>添加属性</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)"> 1</span><span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 2</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 移动数据事件
</span><span style="color: rgba(0, 128, 128, 1)"> 3</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 4</span>         
</span><span style="color: rgba(0, 128, 128, 1)"> 5</span>         <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">event</span><span style="color: rgba(0, 0, 0, 1)"> TransferEventHandler Transfered;
</span><span style="color: rgba(0, 128, 128, 1)"> 6</span>
<span style="color: rgba(0, 128, 128, 1)"> 7</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 8</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> The left columns
</span><span style="color: rgba(0, 128, 128, 1)"> 9</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">10</span>         <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> DataGridViewColumnEntity[] leftColumns;
</span><span style="color: rgba(0, 128, 128, 1)">11</span>
<span style="color: rgba(0, 128, 128, 1)">12</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">13</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> Gets or sets the left columns.
</span><span style="color: rgba(0, 128, 128, 1)">14</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">15</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;value&gt;</span><span style="color: rgba(0, 128, 0, 1)">The left columns.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/value&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">16</span>         
</span><span style="color: rgba(0, 128, 128, 1)">17</span>         <span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> DataGridViewColumnEntity[] LeftColumns
</span><span style="color: rgba(0, 128, 128, 1)">18</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)">19</span>             <span style="color: rgba(0, 0, 255, 1)">get</span> { <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> leftColumns; }
</span><span style="color: rgba(0, 128, 128, 1)">20</span>             <span style="color: rgba(0, 0, 255, 1)">set</span>
<span style="color: rgba(0, 128, 128, 1)">21</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">22</span>               leftColumns =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)">23</span>               <span style="color: rgba(0, 0, 255, 1)">this</span>.dgvLeft.Columns =<span style="color: rgba(0, 0, 0, 1)"> leftColumns.ToList();
</span><span style="color: rgba(0, 128, 128, 1)">24</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">25</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">26</span>
<span style="color: rgba(0, 128, 128, 1)">27</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">28</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> The right columns
</span><span style="color: rgba(0, 128, 128, 1)">29</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">30</span>         <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> DataGridViewColumnEntity[] rightColumns;
</span><span style="color: rgba(0, 128, 128, 1)">31</span>
<span style="color: rgba(0, 128, 128, 1)">32</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">33</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> Gets or sets the right columns.
</span><span style="color: rgba(0, 128, 128, 1)">34</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">35</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;value&gt;</span><span style="color: rgba(0, 128, 0, 1)">The right columns.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/value&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">36</span>         
</span><span style="color: rgba(0, 128, 128, 1)">37</span>         <span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> DataGridViewColumnEntity[] RightColumns
</span><span style="color: rgba(0, 128, 128, 1)">38</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)">39</span>             <span style="color: rgba(0, 0, 255, 1)">get</span> { <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> rightColumns; }
</span><span style="color: rgba(0, 128, 128, 1)">40</span>             <span style="color: rgba(0, 0, 255, 1)">set</span>
<span style="color: rgba(0, 128, 128, 1)">41</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">42</span>               rightColumns =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)">43</span>               <span style="color: rgba(0, 0, 255, 1)">this</span>.dgvRight.Columns =<span style="color: rgba(0, 0, 0, 1)"> leftColumns.ToList();
</span><span style="color: rgba(0, 128, 128, 1)">44</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">45</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">46</span>
<span style="color: rgba(0, 128, 128, 1)">47</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">48</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> The left data source
</span><span style="color: rgba(0, 128, 128, 1)">49</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">50</span>         <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)">[] leftDataSource;
</span><span style="color: rgba(0, 128, 128, 1)">51</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">52</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右列表必须设置相同类型的数据源列表,如果为空必须为长度为0的数组
</span><span style="color: rgba(0, 128, 128, 1)">53</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">54</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;value&gt;</span><span style="color: rgba(0, 128, 0, 1)">The left data source.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/value&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">55</span>         
</span><span style="color: rgba(0, 128, 128, 1)">56</span>         <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)">[] LeftDataSource
</span><span style="color: rgba(0, 128, 128, 1)">57</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)">58</span>             <span style="color: rgba(0, 0, 255, 1)">get</span> { <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> leftDataSource; }
</span><span style="color: rgba(0, 128, 128, 1)">59</span>             <span style="color: rgba(0, 0, 255, 1)">set</span>
<span style="color: rgba(0, 128, 128, 1)">60</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">61</span>               leftDataSource =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)">62</span>               dgvLeft.DataSource =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)">63</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">64</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">65</span>
<span style="color: rgba(0, 128, 128, 1)">66</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">67</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> The right data source
</span><span style="color: rgba(0, 128, 128, 1)">68</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">69</span>         <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)">[] rightDataSource;
</span><span style="color: rgba(0, 128, 128, 1)">70</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">71</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右列表必须设置相同类型的数据源列表,如果为空必须为长度为0的数组
</span><span style="color: rgba(0, 128, 128, 1)">72</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">73</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;value&gt;</span><span style="color: rgba(0, 128, 0, 1)">The left data source.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/value&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">74</span>         
</span><span style="color: rgba(0, 128, 128, 1)">75</span>         <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)">[] RightDataSource
</span><span style="color: rgba(0, 128, 128, 1)">76</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)">77</span>             <span style="color: rgba(0, 0, 255, 1)">get</span> { <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> rightDataSource; }
</span><span style="color: rgba(0, 128, 128, 1)">78</span>             <span style="color: rgba(0, 0, 255, 1)">set</span>
<span style="color: rgba(0, 128, 128, 1)">79</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">80</span>               rightDataSource =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)">81</span>               dgvRight.DataSource =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)">82</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">83</span>         }</pre>
</div>
<p>处理左右移动按钮事件</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)"> 1</span> <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 2</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> Handles the BtnClick event of the btnRight control.
</span><span style="color: rgba(0, 128, 128, 1)"> 3</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 4</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;param name="sender"&gt;</span><span style="color: rgba(0, 128, 0, 1)">The source of the event.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/param&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 5</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;param name="e"&gt;</span><span style="color: rgba(0, 128, 0, 1)">The </span><span style="color: rgba(128, 128, 128, 1)">&lt;see cref="EventArgs"/&gt;</span><span style="color: rgba(0, 128, 0, 1)"> instance containing the event data.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/param&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 6</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;exception cref="System.Exception"&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 7</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右数据源列表不能为空
</span><span style="color: rgba(0, 128, 128, 1)"> 8</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> or
</span><span style="color: rgba(0, 128, 128, 1)"> 9</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右数据源列表类型不一致,无法进行操作
</span><span style="color: rgba(0, 128, 128, 1)">10</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/exception&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">11</span>         <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span> btnRight_BtnClick(<span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)"> sender, EventArgs e)
</span><span style="color: rgba(0, 128, 128, 1)">12</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)">13</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (LeftDataSource == <span style="color: rgba(0, 0, 255, 1)">null</span> || RightDataSource == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">14</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">15</span>               <span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> Exception(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">左右数据源列表不能为空</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">16</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">17</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (LeftDataSource.GetType() !=<span style="color: rgba(0, 0, 0, 1)"> RightDataSource.GetType())
</span><span style="color: rgba(0, 128, 128, 1)">18</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">19</span>               <span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> Exception(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">左右数据源列表类型不一致,无法进行操作</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">20</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">21</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (dgvLeft.SelectRows == <span style="color: rgba(0, 0, 255, 1)">null</span> || dgvLeft.SelectRows.Count &lt;= <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">22</span>               <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">23</span>             List&lt;<span style="color: rgba(0, 0, 255, 1)">object</span>&gt; lst = <span style="color: rgba(0, 0, 255, 1)">new</span> List&lt;<span style="color: rgba(0, 0, 255, 1)">object</span>&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">24</span>             dgvLeft.SelectRows.ForEach(p =&gt;
<span style="color: rgba(0, 128, 128, 1)">25</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">26</span> <span style="color: rgba(0, 0, 0, 1)">                lst.Add(p.DataSource);
</span><span style="color: rgba(0, 128, 128, 1)">27</span>               p.IsChecked = <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">28</span> <span style="color: rgba(0, 0, 0, 1)">            });
</span><span style="color: rgba(0, 128, 128, 1)">29</span>             <span style="color: rgba(0, 0, 255, 1)">var</span> lstRight =<span style="color: rgba(0, 0, 0, 1)"> RightDataSource.ToList();
</span><span style="color: rgba(0, 128, 128, 1)">30</span> <span style="color: rgba(0, 0, 0, 1)">            lstRight.AddRange(lst);
</span><span style="color: rgba(0, 128, 128, 1)">31</span>             <span style="color: rgba(0, 0, 255, 1)">var</span> lstLeft =<span style="color: rgba(0, 0, 0, 1)"> LeftDataSource.ToList();
</span><span style="color: rgba(0, 128, 128, 1)">32</span>             lstLeft.RemoveAll(p =&gt;<span style="color: rgba(0, 0, 0, 1)"> lst.Contains(p));
</span><span style="color: rgba(0, 128, 128, 1)">33</span>             RightDataSource =<span style="color: rgba(0, 0, 0, 1)"> lstRight.ToArray();
</span><span style="color: rgba(0, 128, 128, 1)">34</span>             LeftDataSource =<span style="color: rgba(0, 0, 0, 1)"> lstLeft.ToArray();
</span><span style="color: rgba(0, 128, 128, 1)">35</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (Transfered != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">36</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">37</span>               Transfered(<span style="color: rgba(0, 0, 255, 1)">this</span>, <span style="color: rgba(0, 0, 255, 1)">new</span> TransferEventArgs() { TransferDataSource = lst.ToArray(), ToRightOrLeft = <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)"> });
</span><span style="color: rgba(0, 128, 128, 1)">38</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">39</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">40</span>
<span style="color: rgba(0, 128, 128, 1)">41</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">42</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> Handles the BtnClick event of the btnLeft control.
</span><span style="color: rgba(0, 128, 128, 1)">43</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">44</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;param name="sender"&gt;</span><span style="color: rgba(0, 128, 0, 1)">The source of the event.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/param&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">45</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;param name="e"&gt;</span><span style="color: rgba(0, 128, 0, 1)">The </span><span style="color: rgba(128, 128, 128, 1)">&lt;see cref="EventArgs"/&gt;</span><span style="color: rgba(0, 128, 0, 1)"> instance containing the event data.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/param&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">46</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;exception cref="System.Exception"&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">47</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右数据源列表不能为空
</span><span style="color: rgba(0, 128, 128, 1)">48</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> or
</span><span style="color: rgba(0, 128, 128, 1)">49</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右数据源列表类型不一致,无法进行操作
</span><span style="color: rgba(0, 128, 128, 1)">50</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/exception&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">51</span>         <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span> btnLeft_BtnClick(<span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)"> sender, EventArgs e)
</span><span style="color: rgba(0, 128, 128, 1)">52</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)">53</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (LeftDataSource == <span style="color: rgba(0, 0, 255, 1)">null</span> || RightDataSource == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">54</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">55</span>               <span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> Exception(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">左右数据源列表不能为空</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">56</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">57</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (LeftDataSource.GetType() !=<span style="color: rgba(0, 0, 0, 1)"> RightDataSource.GetType())
</span><span style="color: rgba(0, 128, 128, 1)">58</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">59</span>               <span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> Exception(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">左右数据源列表类型不一致,无法进行操作</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">60</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">61</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (dgvRight.SelectRows == <span style="color: rgba(0, 0, 255, 1)">null</span> || dgvRight.SelectRows.Count &lt;= <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">62</span>               <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">63</span>             List&lt;<span style="color: rgba(0, 0, 255, 1)">object</span>&gt; lst = <span style="color: rgba(0, 0, 255, 1)">new</span> List&lt;<span style="color: rgba(0, 0, 255, 1)">object</span>&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">64</span>             dgvRight.SelectRows.ForEach(p =&gt;
<span style="color: rgba(0, 128, 128, 1)">65</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">66</span> <span style="color: rgba(0, 0, 0, 1)">                lst.Add(p.DataSource);
</span><span style="color: rgba(0, 128, 128, 1)">67</span>               p.IsChecked = <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">68</span> <span style="color: rgba(0, 0, 0, 1)">            });
</span><span style="color: rgba(0, 128, 128, 1)">69</span>             <span style="color: rgba(0, 0, 255, 1)">var</span> lstLeft =<span style="color: rgba(0, 0, 0, 1)"> LeftDataSource.ToList();
</span><span style="color: rgba(0, 128, 128, 1)">70</span> <span style="color: rgba(0, 0, 0, 1)">            lstLeft.AddRange(lst);
</span><span style="color: rgba(0, 128, 128, 1)">71</span>             <span style="color: rgba(0, 0, 255, 1)">var</span> lstRight =<span style="color: rgba(0, 0, 0, 1)"> RightDataSource.ToList();
</span><span style="color: rgba(0, 128, 128, 1)">72</span>             lstRight.RemoveAll(p =&gt;<span style="color: rgba(0, 0, 0, 1)"> lst.Contains(p));
</span><span style="color: rgba(0, 128, 128, 1)">73</span>             RightDataSource =<span style="color: rgba(0, 0, 0, 1)"> lstRight.ToArray();
</span><span style="color: rgba(0, 128, 128, 1)">74</span>             LeftDataSource =<span style="color: rgba(0, 0, 0, 1)"> lstLeft.ToArray();
</span><span style="color: rgba(0, 128, 128, 1)">75</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (Transfered != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">76</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">77</span>               Transfered(<span style="color: rgba(0, 0, 255, 1)">this</span>, <span style="color: rgba(0, 0, 255, 1)">new</span> TransferEventArgs() { TransferDataSource = lst.ToArray(), ToRightOrLeft = <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)"> });
</span><span style="color: rgba(0, 128, 128, 1)">78</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">79</span>         }</pre>
</div>
<p>完整代码</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> ***********************************************************************
</span><span style="color: rgba(0, 128, 128, 1)">2</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Assembly         : HZH_Controls
</span><span style="color: rgba(0, 128, 128, 1)">3</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Created          : 2019-10-10
</span><span style="color: rgba(0, 128, 128, 1)">4</span> <span style="color: rgba(0, 128, 0, 1)">//</span>
<span style="color: rgba(0, 128, 128, 1)">5</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> ***********************************************************************
</span><span style="color: rgba(0, 128, 128, 1)">6</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> &lt;copyright file="UCTransfer.cs"&gt;
</span><span style="color: rgba(0, 128, 128, 1)">7</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">   Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
</span><span style="color: rgba(0, 128, 128, 1)">8</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> &lt;/copyright&gt;
</span><span style="color: rgba(0, 128, 128, 1)">9</span> <span style="color: rgba(0, 128, 0, 1)">//</span>
<span style="color: rgba(0, 128, 128, 1)"> 10</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Blog: </span><span style="color: rgba(0, 128, 0, 1); text-decoration: underline">https://www.cnblogs.com/bfyx</span>
<span style="color: rgba(0, 128, 128, 1)"> 11</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> GitHub:</span><span style="color: rgba(0, 128, 0, 1); text-decoration: underline">https://github.com/kwwwvagaa/NetWinformControl</span>
<span style="color: rgba(0, 128, 128, 1)"> 12</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> gitee:</span><span style="color: rgba(0, 128, 0, 1); text-decoration: underline">https://gitee.com/kwwwvagaa/net_winform_custom_control.git</span>
<span style="color: rgba(0, 128, 128, 1)"> 13</span> <span style="color: rgba(0, 128, 0, 1)">//</span>
<span style="color: rgba(0, 128, 128, 1)"> 14</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> If you use this code, please keep this note.
</span><span style="color: rgba(0, 128, 128, 1)"> 15</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> ***********************************************************************</span>
<span style="color: rgba(0, 128, 128, 1)"> 16</span> <span style="color: rgba(0, 0, 255, 1)">using</span><span style="color: rgba(0, 0, 0, 1)"> System;
</span><span style="color: rgba(0, 128, 128, 1)"> 17</span> <span style="color: rgba(0, 0, 255, 1)">using</span><span style="color: rgba(0, 0, 0, 1)"> System.Collections.Generic;
</span><span style="color: rgba(0, 128, 128, 1)"> 18</span> <span style="color: rgba(0, 0, 255, 1)">using</span><span style="color: rgba(0, 0, 0, 1)"> System.ComponentModel;
</span><span style="color: rgba(0, 128, 128, 1)"> 19</span> <span style="color: rgba(0, 0, 255, 1)">using</span><span style="color: rgba(0, 0, 0, 1)"> System.Drawing;
</span><span style="color: rgba(0, 128, 128, 1)"> 20</span> <span style="color: rgba(0, 0, 255, 1)">using</span><span style="color: rgba(0, 0, 0, 1)"> System.Data;
</span><span style="color: rgba(0, 128, 128, 1)"> 21</span> <span style="color: rgba(0, 0, 255, 1)">using</span><span style="color: rgba(0, 0, 0, 1)"> System.Linq;
</span><span style="color: rgba(0, 128, 128, 1)"> 22</span> <span style="color: rgba(0, 0, 255, 1)">using</span><span style="color: rgba(0, 0, 0, 1)"> System.Text;
</span><span style="color: rgba(0, 128, 128, 1)"> 23</span> <span style="color: rgba(0, 0, 255, 1)">using</span><span style="color: rgba(0, 0, 0, 1)"> System.Windows.Forms;
</span><span style="color: rgba(0, 128, 128, 1)"> 24</span>
<span style="color: rgba(0, 128, 128, 1)"> 25</span> <span style="color: rgba(0, 0, 255, 1)">namespace</span><span style="color: rgba(0, 0, 0, 1)"> HZH_Controls.Controls
</span><span style="color: rgba(0, 128, 128, 1)"> 26</span> <span style="color: rgba(0, 0, 0, 1)">{
</span><span style="color: rgba(0, 128, 128, 1)"> 27</span>   <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 28</span>   <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> Class UCTransfer.
</span><span style="color: rgba(0, 128, 128, 1)"> 29</span>   <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> Implements the </span><span style="color: rgba(128, 128, 128, 1)">&lt;see cref="System.Windows.Forms.UserControl" /&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 30</span>   <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 31</span>   <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;seealso cref="System.Windows.Forms.UserControl" /&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 32</span>   
</span><span style="color: rgba(0, 128, 128, 1)"> 33</span>   <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">partial</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> UCTransfer : UserControl
</span><span style="color: rgba(0, 128, 128, 1)"> 34</span> <span style="color: rgba(0, 0, 0, 1)">    {
</span><span style="color: rgba(0, 128, 128, 1)"> 35</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 36</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 移动数据事件
</span><span style="color: rgba(0, 128, 128, 1)"> 37</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 38</span>         
</span><span style="color: rgba(0, 128, 128, 1)"> 39</span>         <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">event</span><span style="color: rgba(0, 0, 0, 1)"> TransferEventHandler Transfered;
</span><span style="color: rgba(0, 128, 128, 1)"> 40</span>
<span style="color: rgba(0, 128, 128, 1)"> 41</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 42</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> The left columns
</span><span style="color: rgba(0, 128, 128, 1)"> 43</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 44</span>         <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> DataGridViewColumnEntity[] leftColumns;
</span><span style="color: rgba(0, 128, 128, 1)"> 45</span>
<span style="color: rgba(0, 128, 128, 1)"> 46</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 47</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> Gets or sets the left columns.
</span><span style="color: rgba(0, 128, 128, 1)"> 48</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 49</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;value&gt;</span><span style="color: rgba(0, 128, 0, 1)">The left columns.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/value&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 50</span>         
</span><span style="color: rgba(0, 128, 128, 1)"> 51</span>         <span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> DataGridViewColumnEntity[] LeftColumns
</span><span style="color: rgba(0, 128, 128, 1)"> 52</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)"> 53</span>             <span style="color: rgba(0, 0, 255, 1)">get</span> { <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> leftColumns; }
</span><span style="color: rgba(0, 128, 128, 1)"> 54</span>             <span style="color: rgba(0, 0, 255, 1)">set</span>
<span style="color: rgba(0, 128, 128, 1)"> 55</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)"> 56</span>               leftColumns =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)"> 57</span>               <span style="color: rgba(0, 0, 255, 1)">this</span>.dgvLeft.Columns =<span style="color: rgba(0, 0, 0, 1)"> leftColumns.ToList();
</span><span style="color: rgba(0, 128, 128, 1)"> 58</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)"> 59</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)"> 60</span>
<span style="color: rgba(0, 128, 128, 1)"> 61</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 62</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> The right columns
</span><span style="color: rgba(0, 128, 128, 1)"> 63</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 64</span>         <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> DataGridViewColumnEntity[] rightColumns;
</span><span style="color: rgba(0, 128, 128, 1)"> 65</span>
<span style="color: rgba(0, 128, 128, 1)"> 66</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 67</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> Gets or sets the right columns.
</span><span style="color: rgba(0, 128, 128, 1)"> 68</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 69</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;value&gt;</span><span style="color: rgba(0, 128, 0, 1)">The right columns.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/value&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 70</span>         
</span><span style="color: rgba(0, 128, 128, 1)"> 71</span>         <span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> DataGridViewColumnEntity[] RightColumns
</span><span style="color: rgba(0, 128, 128, 1)"> 72</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)"> 73</span>             <span style="color: rgba(0, 0, 255, 1)">get</span> { <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> rightColumns; }
</span><span style="color: rgba(0, 128, 128, 1)"> 74</span>             <span style="color: rgba(0, 0, 255, 1)">set</span>
<span style="color: rgba(0, 128, 128, 1)"> 75</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)"> 76</span>               rightColumns =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)"> 77</span>               <span style="color: rgba(0, 0, 255, 1)">this</span>.dgvRight.Columns =<span style="color: rgba(0, 0, 0, 1)"> leftColumns.ToList();
</span><span style="color: rgba(0, 128, 128, 1)"> 78</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)"> 79</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)"> 80</span>
<span style="color: rgba(0, 128, 128, 1)"> 81</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 82</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> The left data source
</span><span style="color: rgba(0, 128, 128, 1)"> 83</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 84</span>         <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)">[] leftDataSource;
</span><span style="color: rgba(0, 128, 128, 1)"> 85</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 86</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右列表必须设置相同类型的数据源列表,如果为空必须为长度为0的数组
</span><span style="color: rgba(0, 128, 128, 1)"> 87</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 88</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;value&gt;</span><span style="color: rgba(0, 128, 0, 1)">The left data source.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/value&gt;</span>
<span style="color: rgba(0, 128, 128, 1)"> 89</span>         
</span><span style="color: rgba(0, 128, 128, 1)"> 90</span>         <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)">[] LeftDataSource
</span><span style="color: rgba(0, 128, 128, 1)"> 91</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)"> 92</span>             <span style="color: rgba(0, 0, 255, 1)">get</span> { <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> leftDataSource; }
</span><span style="color: rgba(0, 128, 128, 1)"> 93</span>             <span style="color: rgba(0, 0, 255, 1)">set</span>
<span style="color: rgba(0, 128, 128, 1)"> 94</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)"> 95</span>               leftDataSource =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)"> 96</span>               dgvLeft.DataSource =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)"> 97</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)"> 98</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)"> 99</span>
<span style="color: rgba(0, 128, 128, 1)">100</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">101</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> The right data source
</span><span style="color: rgba(0, 128, 128, 1)">102</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">103</span>         <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)">[] rightDataSource;
</span><span style="color: rgba(0, 128, 128, 1)">104</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">105</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右列表必须设置相同类型的数据源列表,如果为空必须为长度为0的数组
</span><span style="color: rgba(0, 128, 128, 1)">106</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">107</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;value&gt;</span><span style="color: rgba(0, 128, 0, 1)">The left data source.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/value&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">108</span>         
</span><span style="color: rgba(0, 128, 128, 1)">109</span>         <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)">[] RightDataSource
</span><span style="color: rgba(0, 128, 128, 1)">110</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)">111</span>             <span style="color: rgba(0, 0, 255, 1)">get</span> { <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> rightDataSource; }
</span><span style="color: rgba(0, 128, 128, 1)">112</span>             <span style="color: rgba(0, 0, 255, 1)">set</span>
<span style="color: rgba(0, 128, 128, 1)">113</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">114</span>               rightDataSource =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)">115</span>               dgvRight.DataSource =<span style="color: rgba(0, 0, 0, 1)"> value;
</span><span style="color: rgba(0, 128, 128, 1)">116</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">117</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">118</span>
<span style="color: rgba(0, 128, 128, 1)">119</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">120</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> Initializes a new instance of the </span><span style="color: rgba(128, 128, 128, 1)">&lt;see cref="UCTransfer"/&gt;</span><span style="color: rgba(0, 128, 0, 1)"> class.
</span><span style="color: rgba(0, 128, 128, 1)">121</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">122</span>         <span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> UCTransfer()
</span><span style="color: rgba(0, 128, 128, 1)">123</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)">124</span> <span style="color: rgba(0, 0, 0, 1)">            InitializeComponent();
</span><span style="color: rgba(0, 128, 128, 1)">125</span>             dgvLeft.IsCloseAutoHeight = <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">126</span>             dgvRight.IsCloseAutoHeight = <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">127</span>             LeftColumns = <span style="color: rgba(0, 0, 255, 1)">new</span> DataGridViewColumnEntity[<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">];
</span><span style="color: rgba(0, 128, 128, 1)">128</span>             RightColumns = <span style="color: rgba(0, 0, 255, 1)">new</span> DataGridViewColumnEntity[<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">];
</span><span style="color: rgba(0, 128, 128, 1)">129</span>             LeftDataSource = <span style="color: rgba(0, 0, 255, 1)">new</span> <span style="color: rgba(0, 0, 255, 1)">object</span>[<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">];
</span><span style="color: rgba(0, 128, 128, 1)">130</span>             RightDataSource = <span style="color: rgba(0, 0, 255, 1)">new</span> <span style="color: rgba(0, 0, 255, 1)">object</span>[<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">];
</span><span style="color: rgba(0, 128, 128, 1)">131</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">132</span>
<span style="color: rgba(0, 128, 128, 1)">133</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">134</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> Handles the BtnClick event of the btnRight control.
</span><span style="color: rgba(0, 128, 128, 1)">135</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">136</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;param name="sender"&gt;</span><span style="color: rgba(0, 128, 0, 1)">The source of the event.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/param&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">137</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;param name="e"&gt;</span><span style="color: rgba(0, 128, 0, 1)">The </span><span style="color: rgba(128, 128, 128, 1)">&lt;see cref="EventArgs"/&gt;</span><span style="color: rgba(0, 128, 0, 1)"> instance containing the event data.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/param&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">138</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;exception cref="System.Exception"&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">139</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右数据源列表不能为空
</span><span style="color: rgba(0, 128, 128, 1)">140</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> or
</span><span style="color: rgba(0, 128, 128, 1)">141</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右数据源列表类型不一致,无法进行操作
</span><span style="color: rgba(0, 128, 128, 1)">142</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/exception&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">143</span>         <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span> btnRight_BtnClick(<span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)"> sender, EventArgs e)
</span><span style="color: rgba(0, 128, 128, 1)">144</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)">145</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (LeftDataSource == <span style="color: rgba(0, 0, 255, 1)">null</span> || RightDataSource == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">146</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">147</span>               <span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> Exception(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">左右数据源列表不能为空</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">148</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">149</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (LeftDataSource.GetType() !=<span style="color: rgba(0, 0, 0, 1)"> RightDataSource.GetType())
</span><span style="color: rgba(0, 128, 128, 1)">150</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">151</span>               <span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> Exception(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">左右数据源列表类型不一致,无法进行操作</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">152</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">153</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (dgvLeft.SelectRows == <span style="color: rgba(0, 0, 255, 1)">null</span> || dgvLeft.SelectRows.Count &lt;= <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">154</span>               <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">155</span>             List&lt;<span style="color: rgba(0, 0, 255, 1)">object</span>&gt; lst = <span style="color: rgba(0, 0, 255, 1)">new</span> List&lt;<span style="color: rgba(0, 0, 255, 1)">object</span>&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">156</span>             dgvLeft.SelectRows.ForEach(p =&gt;
<span style="color: rgba(0, 128, 128, 1)">157</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">158</span> <span style="color: rgba(0, 0, 0, 1)">                lst.Add(p.DataSource);
</span><span style="color: rgba(0, 128, 128, 1)">159</span>               p.IsChecked = <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">160</span> <span style="color: rgba(0, 0, 0, 1)">            });
</span><span style="color: rgba(0, 128, 128, 1)">161</span>             <span style="color: rgba(0, 0, 255, 1)">var</span> lstRight =<span style="color: rgba(0, 0, 0, 1)"> RightDataSource.ToList();
</span><span style="color: rgba(0, 128, 128, 1)">162</span> <span style="color: rgba(0, 0, 0, 1)">            lstRight.AddRange(lst);
</span><span style="color: rgba(0, 128, 128, 1)">163</span>             <span style="color: rgba(0, 0, 255, 1)">var</span> lstLeft =<span style="color: rgba(0, 0, 0, 1)"> LeftDataSource.ToList();
</span><span style="color: rgba(0, 128, 128, 1)">164</span>             lstLeft.RemoveAll(p =&gt;<span style="color: rgba(0, 0, 0, 1)"> lst.Contains(p));
</span><span style="color: rgba(0, 128, 128, 1)">165</span>             RightDataSource =<span style="color: rgba(0, 0, 0, 1)"> lstRight.ToArray();
</span><span style="color: rgba(0, 128, 128, 1)">166</span>             LeftDataSource =<span style="color: rgba(0, 0, 0, 1)"> lstLeft.ToArray();
</span><span style="color: rgba(0, 128, 128, 1)">167</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (Transfered != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">168</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">169</span>               Transfered(<span style="color: rgba(0, 0, 255, 1)">this</span>, <span style="color: rgba(0, 0, 255, 1)">new</span> TransferEventArgs() { TransferDataSource = lst.ToArray(), ToRightOrLeft = <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)"> });
</span><span style="color: rgba(0, 128, 128, 1)">170</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">171</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">172</span>
<span style="color: rgba(0, 128, 128, 1)">173</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">174</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> Handles the BtnClick event of the btnLeft control.
</span><span style="color: rgba(0, 128, 128, 1)">175</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">176</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;param name="sender"&gt;</span><span style="color: rgba(0, 128, 0, 1)">The source of the event.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/param&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">177</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;param name="e"&gt;</span><span style="color: rgba(0, 128, 0, 1)">The </span><span style="color: rgba(128, 128, 128, 1)">&lt;see cref="EventArgs"/&gt;</span><span style="color: rgba(0, 128, 0, 1)"> instance containing the event data.</span><span style="color: rgba(128, 128, 128, 1)">&lt;/param&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">178</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;exception cref="System.Exception"&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">179</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右数据源列表不能为空
</span><span style="color: rgba(0, 128, 128, 1)">180</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> or
</span><span style="color: rgba(0, 128, 128, 1)">181</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 左右数据源列表类型不一致,无法进行操作
</span><span style="color: rgba(0, 128, 128, 1)">182</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/exception&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">183</span>         <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span> btnLeft_BtnClick(<span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)"> sender, EventArgs e)
</span><span style="color: rgba(0, 128, 128, 1)">184</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)">185</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (LeftDataSource == <span style="color: rgba(0, 0, 255, 1)">null</span> || RightDataSource == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">186</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">187</span>               <span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> Exception(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">左右数据源列表不能为空</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">188</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">189</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (LeftDataSource.GetType() !=<span style="color: rgba(0, 0, 0, 1)"> RightDataSource.GetType())
</span><span style="color: rgba(0, 128, 128, 1)">190</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">191</span>               <span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> Exception(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">左右数据源列表类型不一致,无法进行操作</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">192</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">193</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (dgvRight.SelectRows == <span style="color: rgba(0, 0, 255, 1)">null</span> || dgvRight.SelectRows.Count &lt;= <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">194</span>               <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">195</span>             List&lt;<span style="color: rgba(0, 0, 255, 1)">object</span>&gt; lst = <span style="color: rgba(0, 0, 255, 1)">new</span> List&lt;<span style="color: rgba(0, 0, 255, 1)">object</span>&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">196</span>             dgvRight.SelectRows.ForEach(p =&gt;
<span style="color: rgba(0, 128, 128, 1)">197</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">198</span> <span style="color: rgba(0, 0, 0, 1)">                lst.Add(p.DataSource);
</span><span style="color: rgba(0, 128, 128, 1)">199</span>               p.IsChecked = <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">200</span> <span style="color: rgba(0, 0, 0, 1)">            });
</span><span style="color: rgba(0, 128, 128, 1)">201</span>             <span style="color: rgba(0, 0, 255, 1)">var</span> lstLeft =<span style="color: rgba(0, 0, 0, 1)"> LeftDataSource.ToList();
</span><span style="color: rgba(0, 128, 128, 1)">202</span> <span style="color: rgba(0, 0, 0, 1)">            lstLeft.AddRange(lst);
</span><span style="color: rgba(0, 128, 128, 1)">203</span>             <span style="color: rgba(0, 0, 255, 1)">var</span> lstRight =<span style="color: rgba(0, 0, 0, 1)"> RightDataSource.ToList();
</span><span style="color: rgba(0, 128, 128, 1)">204</span>             lstRight.RemoveAll(p =&gt;<span style="color: rgba(0, 0, 0, 1)"> lst.Contains(p));
</span><span style="color: rgba(0, 128, 128, 1)">205</span>             RightDataSource =<span style="color: rgba(0, 0, 0, 1)"> lstRight.ToArray();
</span><span style="color: rgba(0, 128, 128, 1)">206</span>             LeftDataSource =<span style="color: rgba(0, 0, 0, 1)"> lstLeft.ToArray();
</span><span style="color: rgba(0, 128, 128, 1)">207</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (Transfered != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">208</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">209</span>               Transfered(<span style="color: rgba(0, 0, 255, 1)">this</span>, <span style="color: rgba(0, 0, 255, 1)">new</span> TransferEventArgs() { TransferDataSource = lst.ToArray(), ToRightOrLeft = <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)"> });
</span><span style="color: rgba(0, 128, 128, 1)">210</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">211</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">212</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">213</span> }</pre>
</div>
<p>&nbsp;</p>
<h1>最后的话</h1>
<p>如果你喜欢的话,请到&nbsp;https://gitee.com/kwwwvagaa/net_winform_custom_control&nbsp;点个星星吧</p>

</div>
<div id="MySignature" role="contentinfo">
    <div style="display: block" id="MySignature"><p style="background: rgb(230, 250, 230); padding: 10px 10px 10px 10px; border: 1px dashed rgb(224, 224, 224); font-family: 微软雅黑; font-size: 13px; text-indent: 0em">
作者:冰封一夏
<br>
出处:http://www.cnblogs.com/bfyx/
<br>
HZHControls官网:http://www.hzhcontrols.cn
<br>
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
<br>且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
<br>
GitHub:https://github.com/kwwwvagaa/NetWinformControl
<br>
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
</p>
</div><br><br>
来源:https://www.cnblogs.com/bfyx/p/11646790.html
頁: [1]
查看完整版本: (八十二)c#Winform自定义控件-穿梭框-HZHControls