C# winform通过按钮上移下移 解决了datasource绑定问题
事件代码:
private void btn_frmDicType_MoveUp_Click(object sender, EventArgs e)
{
int lstLength = this.lst_frmDic_Type_Property.Items.Count;
int ilstSelect = this.lst_frmDic_Type_Property.SelectedIndex;
if (ilstSelect == 0)
{
MessageBox.Show("已在当前最顶端,无法再移动...");
return;
}
else if (lstLength > ilstSelect && ilstSelect > 0)
{
DataTable dt = (DataTable)lst_frmDic_Type_Property.DataSource;
DataTable dtCopy = new DataTable();
dtCopy.Clear();
dtCopy = dt.Copy();//拷贝dt
dtCopy.Rows[ilstSelect].Delete();
dtCopy.Rows[ilstSelect - 1].Delete();
DataRow drClone1 = dtCopy.NewRow();
DataRow drClone2 = dtCopy.NewRow();
drClone1.ItemArray = dt.Rows[ilstSelect].ItemArray;//需要上移的
drClone2.ItemArray = dt.Rows[ilstSelect - 1].ItemArray;//被移到下面
dtCopy.Rows.InsertAt(drClone1, ilstSelect - 1);
dtCopy.Rows.InsertAt(drClone2, ilstSelect);
//删除未彻底删除的2行,需要使用datatable.AcceptChanges()方法来提交修改.
dtCopy.AcceptChanges();
lst_frmDic_Type_Property.DataSource = dtCopy;
this.lst_frmDic_Type_Property.SelectedIndex = ilstSelect - 1;
//操作数据库,修改顺序号
//得到id号
int id1 = Convert.ToInt32(dt.Rows[ilstSelect]["ID"].ToString());
int id2 = Convert.ToInt32(dt.Rows[ilstSelect - 1]["ID"].ToString());
// 根据id号,得到顺序号
int order1 = Convert.ToInt32(frmDic_BLL.FrmDic_Dic_GetDICOrderById(id1).Tables[0].Rows[0]["DICOrder"]);
int order2 = Convert.ToInt32(frmDic_BLL.FrmDic_Dic_GetDICOrderById(id2).Tables[0].Rows[0]["DICOrder"]);
//根据id号,修改顺序号
frmDic_BLL.FrmDic_Dic_UpdataPropertyDICOrderByID(id1, order2);
frmDic_BLL.FrmDic_Dic_UpdataPropertyDICOrderByID(id2, order1);
}
else
{
return;
}
}
private void btn_frmDicType_MoveDown_Click(object sender, EventArgs e)
{
int lstLength = this.lst_frmDic_Type_Property.Items.Count;
int ilstSelect = this.lst_frmDic_Type_Property.SelectedIndex;
if (ilstSelect == lstLength - 1)
{
MessageBox.Show("已在当前最末端,无法再移动...");
return;
}
else if (lstLength - 1 > ilstSelect && ilstSelect >= 0)
{
DataTable dt = (DataTable)lst_frmDic_Type_Property.DataSource;
DataTable dtCopy = new DataTable();
dtCopy.Clear();
dtCopy = dt.Copy();//拷贝dt
/////////
// delete和remove
//Delete的使用是 datatable.Rows[i].Delete();
//Remove的使用是datatable.Rows.Remove(datatable.Rows[i]);
//这两个的区别是,使用delete后,只是该行被标记为deleted,但是还存在,用Rows.Count来获取行数时,还是删除之前的行数.需要使用datatable.AcceptChanges()方法来提交修改.
dtCopy.Rows[ilstSelect].Delete();
dtCopy.Rows[ilstSelect + 1].Delete();
DataRow drClone1 = dtCopy.NewRow();
DataRow drClone2 = dtCopy.NewRow();
drClone1.ItemArray = dt.Rows[ilstSelect].ItemArray;//需要下移的
drClone2.ItemArray = dt.Rows[ilstSelect + 1].ItemArray;//被移到上面
dtCopy.Rows.InsertAt(drClone1, ilstSelect + 1);
dtCopy.Rows.InsertAt(drClone2, ilstSelect);
//删除未彻底删除的2行,需要使用datatable.AcceptChanges()方法来提交修改.
dtCopy.AcceptChanges();
lst_frmDic_Type_Property.DataSource = dtCopy;
this.lst_frmDic_Type_Property.SelectedIndex = ilstSelect + 1;
//操作数据库,修改顺序号
//得到id号
int id1 = Convert.ToInt32(dt.Rows[ilstSelect]["ID"].ToString());
int id2 = Convert.ToInt32(dt.Rows[ilstSelect + 1]["ID"].ToString());
// 根据id号,得到顺序号
int order1 = Convert.ToInt32(frmDic_BLL.FrmDic_Dic_GetDICOrderById(id1).Tables[0].Rows[0]["DICOrder"]);
int order2 = Convert.ToInt32(frmDic_BLL.FrmDic_Dic_GetDICOrderById(id2).Tables[0].Rows[0]["DICOrder"]);
//根据id号,修改顺序号
frmDic_BLL.FrmDic_Dic_UpdataPropertyDICOrderByID(id1, order2);
frmDic_BLL.FrmDic_Dic_UpdataPropertyDICOrderByID(id2, order1);
}
else
{
return;
}
}
BLL:
// 根据ID,返回Dic表的顺序号
public DataSet FrmDic_Dic_GetDICOrderById(int strID)
{
return (FrmDic_DAL.FrmDic_Dic_GetDICOrderById(strID));
}
// 根据ID,更新Dic表的顺序号
public void FrmDic_Dic_UpdataPropertyDICOrderByID(int strID, int DICOrder)
{
FrmDic_DAL.FrmDic_Dic_UpdataPropertyDICOrderByID(strID, DICOrder);
}
DAL:
#region "根据ID,更新Dic表的顺序号"
/// <summary>
/// 根据ID,更新Dic表的顺序号
/// </summary>
/// <param name="strID">被修改的id</param>
/// <param name="DICOrder">序号</param>
public static void FrmDic_Dic_UpdataPropertyDICOrderByID(int strID, int DICOrder)
{
string sqlCommand = "FrmDic_Dic_UpdataPropertyDICOrderByID";
SqlParameter[] param ={
new SqlParameter("@strID",SqlDbType.Int),
new SqlParameter("@DICOrder",SqlDbType.Int),
};
param[0].Value = strID;
param[1].Value = DICOrder;
SqlHelper.ExecuteNonQuery(GHGD.Conn.Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
}
#endregion
#region "根据ID,返回Dic表的顺序号"
/// <summary>
/// 根据ID,返回Dic表的顺序号
/// </summary>
/// <param name="strID"></param>
public static DataSet FrmDic_Dic_GetDICOrderById(int strID)
{
string sqlCommand = "FrmDic_Dic_GetDICOrderById";
DataSet ds = new DataSet();
SqlParameter[] param ={
new SqlParameter("@id",strID),
};
//param[0].Value = strID;
SqlHelper.ExecuteDataset(GHGD.Conn.Conn.SqlConn, ds, "FrmDic_Dic_GetDICOrderById", CommandType.StoredProcedure, sqlCommand, param);
if (ds.Tables[0].Rows.Count != 0)
{
ds.Dispose();
return ds;
}
else
{
return null;
}
}
#endregion
存储过程:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER procedure [dbo].[FrmDic_Dic_UpdataPropertyDICOrderByID]
(@strID int,@DICOrder int)
as
begin
update Dic set DICOrder=@DICOrder where ID=@strID
end
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[FrmDic_Dic_GetDICOrderById]
(@id int)
AS
BEGIN
SET NOCOUNT ON;
select DICOrder from Dic where ID = @id
END
C# winform通过按钮上移下移 解决了datasource绑定问题的更多相关文章
- Devexpress WinForm TreeList的三种数据绑定方式(DataSource绑定、AppendNode添加节点、VirtualTreeGetChildNodes(虚拟树加载模式))
第一种:DataSource绑定,这种绑定方式需要设置TreeList的ParentFieldName和KeyFieldName两个属性,这里需要注意的是KeyFieldName的值必须是唯一的. 代 ...
- 聊天界面使用IQKeyboardManager导航栏及整个页面上移的解决方法
问题: 使用第三方库IQKeyboardManager时会使整个页面上移,导航栏页偏移出了显示范围.在聊天界面就会使得上面的消息看不到. 解决方法: 首先说明:在聊天界面使用IQKeyboardMan ...
- jQuery实现表格行上移下移和置顶
jQuery实现表格行上移下移和置顶 我们在操作列表数据的时候,需要将数据行排列顺序进行调整,如上移和下移行,将行数据置顶等,这些操作都可以在前端通过点击按钮来完成,并且伴随着简单的动态效果,轻松实现 ...
- jqgrid 上移下移单元格
在表格中常常需要调整表格中数据的显示顺序,我用的是jqgrid,实现原理就是将表中的行数保存到数据库中,取数据时按行进行排序 1.上移,下移按钮 <a href="javascript ...
- 05_jquery 操作table使tr(数据)整行上移下移
1:ajax请求数据到页面 function GetWorkSpaceList() { GetServerData("get", GetEnterpriseUrl() + &quo ...
- bootstrap与jqueryui按钮冲突的解决
bootstrap与jqueryui按钮冲突的解决 (2013-10-15 14:09:36)转载▼ 标签: 情感 分类: jQuery 参考: http://getbootstrap.com/jav ...
- php修改排序,上移下移
php修改排序,上移下移 /** $UpDown //移动方向,up或down $table //表名 $id //当前移动的ID $id_col //ID字段的名称 $ ...
- JS移动li行数据,点击上移下移(是位置的互换,不是top的偏移量改变)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- table中实现数据上移下移效果
html 由于vue+Element项目中的table,没有开放的上移下移的api,但是能对数据操作,故思路为数组中的一条数据,再重新添加一条数据,办法有点笨,但是好歹也是实现了,望有好的办法的,请留 ...
随机推荐
- Windows提高_1.2遍历进程、遍历模块
进程 什么是进程? 通俗的来讲,进程就是一个运行中的程序,最少包含一个虚拟空间,通常是 4 GB大小,一组提供数据和代码的模块,通产是 dll 和 exe 文件,一个进程内核对象和最少一个线程. 进程 ...
- python实现二叉树的遍历以及基本操作
主要内容: 二叉树遍历(先序.中序.后序.宽度优先遍历)的迭代实现和递归实现: 二叉树的深度,二叉树到叶子节点的所有路径: 首先,先定义二叉树类(python3),代码如下: class TreeNo ...
- ThinkPHP---layer插件
[概论] (1)layer是基于jquery开发的一款美化弹框的插件,主要用于弹框效果的交互.但其他功能和组件也日益完善 官网:http://layer.layui.com 在线手册:http://w ...
- 10Oracle Database 数据表数据查询
Oracle Database 数据表数据查询 DML 数据操纵语言 - 数据的查看和维护 select / insert /delete /update 基本查询语句 Select [distinc ...
- 视频剪辑生成gif格式(php外挂python程序)完美!
接到朋友的需求,朋友是做php的,让我帮忙处理php生成gif的需求.他的项目类似抖音短视频那种,就是展示出来的界面是gif动图,然后点进去是完整的视频. 我想了想,我倒是没做过php生成gif的需求 ...
- 由杭州开往成都的K529次列车
春运期间,在由杭州开往成都的K529次列车上,旅客严重超员.一个靠窗坐着的老大爷正跟邻座的人分享他的幸运经历,原来,他是到上饶的,买的是无座票,上车后抱着侥幸心理事先占了个好座,没想到直到开车也没人上 ...
- 『 Luogu P3205 』 HNOI2010 合唱队
解题思路 设置两个二维数组 $f$ 和 $g$,含义如下. $f[l][r]$ 表示在期望得到的队形中 $l\rightarrow r$ 这段区间初始队形排列的方案数,并且最后一个加入进去的是第 $l ...
- LinuxMint19.1安装搜狗拼音输入法
Installation 1.到搜狗拼音输入法官网下载Linux版. 2.使用dpkg命令安装deb软件包 $ sudo dpkg -i sogoupinyin_2.2.0.0108_amd.deb ...
- linux ltrace-跟踪进程调用库函数的情况
当前位置:硬件 | 监测 | 内核 | Shell / 性能监测与优化 /ltrace ltrace命令是用来跟踪进程调用库函数的情况. 语法 ltrace [option ...] [command ...
- day21 01 包的初识
day21 01包的初识 包:把解决一类问题的模块放在同一个文件夹里面-----包(一个包里面通常会含有_init_.py文件(python2里面必须有),但是后面的就没有要求一定要有了) 同样导入的 ...