mobile中使用vScrollBar解决DataGrid无滚动事件问题
2009-12-12 13:44
525 查看
mobile中的DataGrid没有提供滚动事件,在DataGrid数据编辑中将会遇到很多困扰。
下面提供一种间接方式处理DataGrid的滚动事件。(需设置vScrollBar的LargeChange为1,否则达不到预期效果)
在DataGrid右侧滚动条位置放置一个vScrollBar挡住DataGrid默认的滚动条
在DataGrid的数据绑定事件中设置vScrollBar的Maximum为DataGrid的数据行数
DataGrid的CurrentCellChanged事件中给vScrollBar的Value赋值为当前选中行的Index
vScrollBar的ValueChanged事件中给DataGrid的当前选中Index赋值为vScrollBar的Value
private void Form1_Load(object sender, EventArgs e)
{
vScrollBar.Value = 0;
vScrollBar.Minimum = 0;
vScrollBar.SmallChange = 1;
vScrollBar.LargeChange = 1;
vScrollBar.Enabled = false;
}
private void BindDataGrid(object sender, EventArgs e)
{
SqlCeConnection con = new SqlCeConnection(@"data source=\program files\db.sdf");
SqlCeDataAdapter da = new SqlCeDataAdapter("select * from table1", con);
DataSet ds = new DataSet();
da.Fill(ds);
dataGrid.DataSource = ds.Tables[0];
vScrollBar.Maximum = ds.Tables[0].Rows.Count - 1;
vScrollBar.Enabled = true;
}
private void dg_CurrentCellChanged(object sender, EventArgs e)
{
vScrollBar.Value = dataGrid.CurrentRowIndex;
}
private void vScrollBar_ValueChanged(object sender, EventArgs e)
{
dataGrid.CurrentRowIndex = vScrollBar.Value;
}
下面提供一种间接方式处理DataGrid的滚动事件。(需设置vScrollBar的LargeChange为1,否则达不到预期效果)
在DataGrid右侧滚动条位置放置一个vScrollBar挡住DataGrid默认的滚动条
在DataGrid的数据绑定事件中设置vScrollBar的Maximum为DataGrid的数据行数
DataGrid的CurrentCellChanged事件中给vScrollBar的Value赋值为当前选中行的Index
vScrollBar的ValueChanged事件中给DataGrid的当前选中Index赋值为vScrollBar的Value
private void Form1_Load(object sender, EventArgs e)
{
vScrollBar.Value = 0;
vScrollBar.Minimum = 0;
vScrollBar.SmallChange = 1;
vScrollBar.LargeChange = 1;
vScrollBar.Enabled = false;
}
private void BindDataGrid(object sender, EventArgs e)
{
SqlCeConnection con = new SqlCeConnection(@"data source=\program files\db.sdf");
SqlCeDataAdapter da = new SqlCeDataAdapter("select * from table1", con);
DataSet ds = new DataSet();
da.Fill(ds);
dataGrid.DataSource = ds.Tables[0];
vScrollBar.Maximum = ds.Tables[0].Rows.Count - 1;
vScrollBar.Enabled = true;
}
private void dg_CurrentCellChanged(object sender, EventArgs e)
{
vScrollBar.Value = dataGrid.CurrentRowIndex;
}
private void vScrollBar_ValueChanged(object sender, EventArgs e)
{
dataGrid.CurrentRowIndex = vScrollBar.Value;
}
相关文章推荐
- [原创]JQuery的autoCompleate插件的使用(内含解决Jquery事件与UpdatePanel互斥的问题,只需要在body中改为如下:<body onload=’load()’></body>即可)
- 解决SlideDetailsLayout与ViewPager垂直滚动事件冲突问题
- 使用JS+WebBrowser解决Web打印问题(完成事件)
- 使用iscroll滑动区域内的div onclick事件单击一次触发了两次问题的解决
- 今天在使用iscroll4 做一个简单触屏滚动demo,发现上下拖动的时候总是会回弹,不能看到下面的内容.这个问题苦恼了很久,终于解决
- 解决使用工具栏组件时控件焦点事件的问题
- onclientclick事件使用JS页面会刷新问题解决
- ListView中使用EditText(解决EditText焦点丢失、保存数据以及滚动冲突的问题)
- 今天使用PullToRefreshListView时遇到Item点击事件失效问题,特此记下解决办法
- jquery 解决使用append添加元素后监听事件消失的问题
- sl3中的DataGrid中的数据导出到Excel中 使用csv格式 解决中文是乱码的问题
- Windows线程(六)使用事件机制解决线程同步问题
- 使用Unity3D时,UIScrollView不滚动问题的解决方法
- 解决『回发或回调参数无效。在配置中使用 或在页面中使用 启用了事件验证。』问题
- 解决IE6,IE7下子元素使用position:relative、父元素使用overflow:auto后,子元素不随着滚动条滚动的问题
- 手机端局部滚动问题 overflow-y:auto|scroll无效,使用iscroll解决
- JS中批量给元素绑定事件过程中的相关问题使用闭包解决
- 使用Jquery的鲜活绑定(lively-ness),解决“新添加的元素,事件不可用”的问题
- .net MVC3使用jquery.mobile 解决页面二次跳转不加载的问题