设为首页 加入收藏

TOP

(八十二)c#Winform自定义控件-穿梭框(四)
2019-10-10 18:14:58 】 浏览:571
Tags:八十二 c#Winform 定义 控件 穿梭
ns = new DataGridViewColumnEntity[0]; 129 LeftDataSource = new object[0]; 130 RightDataSource = new object[0]; 131 } 132 133 /// <summary> 134 /// Handles the BtnClick event of the btnRight control. 135 /// </summary> 136 /// <param name="sender">The source of the event.</param> 137 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> 138 /// <exception cref="System.Exception"> 139 /// 左右数据源列表不能为空 140 /// or 141 /// 左右数据源列表类型不一致,无法进行操作 142 /// </exception> 143 private void btnRight_BtnClick(object sender, EventArgs e) 144 { 145 if (LeftDataSource == null || RightDataSource == null) 146 { 147 throw new Exception("左右数据源列表不能为空"); 148 } 149 if (LeftDataSource.GetType() != RightDataSource.GetType()) 150 { 151 throw new Exception("左右数据源列表类型不一致,无法进行操作"); 152 } 153 if (dgvLeft.SelectRows == null || dgvLeft.SelectRows.Count <= 0) 154 return; 155 List<object> lst = new List<object>(); 156 dgvLeft.SelectRows.ForEach(p => 157 { 158 lst.Add(p.DataSource); 159 p.IsChecked = false; 160 }); 161 var lstRight = RightDataSource.ToList(); 162 lstRight.AddRange(lst); 163 var lstLeft = LeftDataSource.ToList(); 164 lstLeft.RemoveAll(p => lst.Contains(p)); 165 RightDataSource = lstRight.ToArray(); 166 LeftDataSource = lstLeft.ToArray(); 167 if (Transfered != null) 168 { 169 Transfered(this, new TransferEventArgs() { TransferDataSource = lst.ToArray(), ToRightOrLeft = true }); 170 } 171 } 172 173 /// <summary> 174 /// Handles the BtnClick event of the btnLeft control. 175 /// </summary> 176 /// <param name="sender">The source of the event.</param> 177 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> 178 /// <exception cref="System.Exception"> 179 /// 左右数据源列表不能为空 180 /// or 181 /// 左右数据源列表类型不一致,无法进行操作 182 /// </exception> 183 private void btnLeft_BtnClick(object sender, EventArgs e) 184 { 185 if (LeftDataSource == null || RightDataSource == null) 186 { 187 throw new Exception("左右数据源列表不能为空"); 188 } 189 if (LeftDataSource.GetType() != RightDataSource.GetType()) 190 { 191 throw new Exception("左右数据源列表类型不一致,无法进行操作"); 192 } 193 if (dgvRight.SelectRows == null || dgvRight.SelectRows.Count <= 0) 194 return; 195 List<object> lst = new List<object>(); 196 dgvRight.SelectRows.ForEach(p => 197 { 198 lst.Add(p.DataSource); 199 p.IsChecked = false; 200 }); 201 var lstLeft = LeftDataSource.ToList(); 202 lstLeft.AddRange(lst); 203 var lstRight = RightDataSource.ToList(); 204 lstRight.RemoveAll(p => lst.Contains(p)); 205 RightDataSource = lstRight.ToArray(); 206 LeftDataSource = lstLeft.ToArray(); 207 if (Transfered != null) 208 { 209 Transfered(this, new TransferEventArgs() { TransferDataSource = lst.ToArray(), ToRightOrLeft = false }); 210 } 211 } 212 } 213 }

 

最后的话

如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星星吧

首页 上一页 1 2 3 4 下一页 尾页 4/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇vscode解决nuget插件不能使用的问.. 下一篇ABP vNext 不使用工作单元为什么..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目