View Full Version : GridView排序问题


xsp
04-09-2007, 03:03 AM
点GridView列标题,进行排序(三角),再选择记录,出现混乱

t-xguo@prcvap.microsoft.com
04-10-2007, 04:18 AM
您好:

所说的GridView是指WinForm下的DataGridView,而不是Asp.net的GridView吧,否则不会有三角符号?另外您所说的出现混乱具体是什么意思?
为了更快的解决问题,希望您能够把问题描述的清晰些,谢谢您的合作和理解。

郭轩
在线技术支持工程师
微软全球技术支持中心
---------------------------------------------------------------------------------------
我们的服务时间:周一至周五9:00-18:00(节假日除外)。我们将在两个工作日(48小时)内提供初始回应,并和您一起研究并解决问题。更多微软新闻组技术支持信息,请访问:http://support.microsoft.com/gp/newsgroupsupport/zh-cn.

回帖时,请在您的新闻组阅读器中使用“回复组(Reply to Group)”,这将帮助其他用户从您的提问中获益
---------------------------------------------------------------------------------------
本贴子以”现状”提供且没有任何担保,同时也没有授予任何权利。

xsp
04-10-2007, 07:38 AM
是在winF下的,就是点列标题排序后,再选择记录进行修改,发现所选择的记录不对
<t-xguo@prcvap.microsoft.com> 写入消息新闻:59d09399-a271-45be-85e7-5426213900f1@ms.shabap01.publicpsswebcat...
> 您好:
>
> 所说的GridView是指WinForm下的DataGridView,而不是Asp.net的GridView吧,否则不会有三角符号?另外您所说的出现混乱具体是什么意思?
> 为了更快的解决问题,希望您能够把问题描述的清晰些,谢谢您的合作和理解。
>
> 郭轩
> 在线技术支持工程师
> 微软全球技术支持中心
> ---------------------------------------------------------------------------------------
> 我们的服务时间:周一至周五9:00-18:00(节假日除外)。我们将在两个工作日(48小时)内提供初始回应,并和您一起研究并解决问题。更多微软新闻组技术支持信息,请访问:http://support.microsoft.com/gp/newsgroupsupport/zh-cn.
>
> 回帖时,请在您的新闻组阅读器中使用“回复组(Reply to Group)”,这将帮助其他用户从您的提问中获益
> ---------------------------------------------------------------------------------------
> 本贴子以”现状”提供且没有任何担保,同时也没有授予任何权利。

t-xguo@prcvap.microsoft.com
04-10-2007, 10:24 AM
您好:

您说所的是不是这样一个问题:
DataGridView column排序前后,DataGridView显示的被选中的记录行不同,这是由于DataGridView只记录当前显示所在的行数,而不是DataSet中记录的行数。
以下提供解决该问题的演示代码:设从Northwind 的Orders数据表中去数据,主键时orderID.

public partial class Form1 : Form
{
private BindingSource source = new BindingSource();
private CurrencyManager manager = null;
private object findVaule = null;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
SqlConnection oSQLConn = new SqlConnection();
oSQLConn.ConnectionString = "Data Source=.\\sqlexpress;Initial Catalog=Northwind;Integrated Security=True";
oSQLConn.Open();
SqlDataAdapter adapter = new SqlDataAdapter(new SqlCommand("Select * from Orders", oSQLConn));
DataSet ds=new DataSet();
adapter.Fill(ds);
DataView dv = ds.Tables[0].DefaultView;
oSQLConn.Close();
this.source.DataSource = dv;
this.dataGridView1.DataSource = dv;
this.manager = (CurrencyManager)this.BindingContext[dv];
}

private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
findVaule = this.dataGridView1.CurrentCell.Value;
}

private void dataGridView1_Sorted(object sender, EventArgs e)
{
manager.Position = source.Find("orderID", Convert.ToInt32(findVaule));
}

即需要处理MouseClick和Sorted事件。


郭轩
在线技术支持工程师
微软全球技术支持中心
---------------------------------------------------------------------------------------
我们的服务时间:周一至周五9:00-18:00(节假日除外)。我们将在两个工作日(48小时)内提供初始回应,并和您一起研究并解决问题。更多微软新闻组技术支持信息,请访问:http://support.microsoft.com/gp/newsgroupsupport/zh-cn.

回帖时,请在您的新闻组阅读器中使用“回复组(Reply to Group)”,这将帮助其他用户从您的提问中获益
---------------------------------------------------------------------------------------
本贴子以”现状”提供且没有任何担保,同时也没有授予任何权利。

xsp
04-11-2007, 02:02 AM
orderID是数据库里的主键吗?
<t-xguo@prcvap.microsoft.com> 写入消息新闻:532078dc-e5b4-4b0f-924b-78c04d9e1de3@ms.shabap01.publicpsswebcat...
> 您好:
>
> 您说所的是不是这样一个问题:
> DataGridView column排序前后,DataGridView显示的被选中的记录行不同,这是由于DataGridView只记录当前显示所在的行数,而不是DataSet中记录的行数。
> 以下提供解决该问题的演示代码:设从Northwind 的Orders数据表中去数据,主键时orderID.
>
> public partial class Form1 : Form
> {
> private BindingSource source = new BindingSource();
> private CurrencyManager manager = null;
> private object findVaule = null;
> public Form1()
> {
> InitializeComponent();
> }
>
> private void button1_Click(object sender, EventArgs e)
> {
> SqlConnection oSQLConn = new SqlConnection();
> oSQLConn.ConnectionString = "Data Source=.\\sqlexpress;Initial
> Catalog=Northwind;Integrated Security=True";
> oSQLConn.Open();
> SqlDataAdapter adapter = new SqlDataAdapter(new
> SqlCommand("Select * from Orders", oSQLConn));
> DataSet ds=new DataSet();
> adapter.Fill(ds);
> DataView dv = ds.Tables[0].DefaultView;
> oSQLConn.Close();
> this.source.DataSource = dv;
> this.dataGridView1.DataSource = dv;
> this.manager = (CurrencyManager)this.BindingContext[dv];
> }
>
> private void dataGridView1_MouseClick(object sender, MouseEventArgs
> e)
> {
> findVaule = this.dataGridView1.CurrentCell.Value;
> }
>
> private void dataGridView1_Sorted(object sender, EventArgs e)
> {
> manager.Position = source.Find("orderID",
> Convert.ToInt32(findVaule));
> }
>
> 即需要处理MouseClick和Sorted事件。
>
>
> 郭轩
> 在线技术支持工程师
> 微软全球技术支持中心
> ---------------------------------------------------------------------------------------
> 我们的服务时间:周一至周五9:00-18:00(节假日除外)。我们将在两个工作日(48小时)内提供初始回应,并和您一起研究并解决问题。更多微软新闻组技术支持信息,请访问:http://support.microsoft.com/gp/newsgroupsupport/zh-cn.
>
> 回帖时,请在您的新闻组阅读器中使用“回复组(Reply to Group)”,这将帮助其他用户从您的提问中获益
> ---------------------------------------------------------------------------------------
> 本贴子以”现状”提供且没有任何担保,同时也没有授予任何权利。

xsp
04-11-2007, 02:25 AM
提示orderID无效
<t-xguo@prcvap.microsoft.com> 写入消息新闻:532078dc-e5b4-4b0f-924b-78c04d9e1de3@ms.shabap01.publicpsswebcat...
> 您好:
>
> 您说所的是不是这样一个问题:
> DataGridView column排序前后,DataGridView显示的被选中的记录行不同,这是由于DataGridView只记录当前显示所在的行数,而不是DataSet中记录的行数。
> 以下提供解决该问题的演示代码:设从Northwind 的Orders数据表中去数据,主键时orderID.
>
> public partial class Form1 : Form
> {
> private BindingSource source = new BindingSource();
> private CurrencyManager manager = null;
> private object findVaule = null;
> public Form1()
> {
> InitializeComponent();
> }
>
> private void button1_Click(object sender, EventArgs e)
> {
> SqlConnection oSQLConn = new SqlConnection();
> oSQLConn.ConnectionString = "Data Source=.\\sqlexpress;Initial
> Catalog=Northwind;Integrated Security=True";
> oSQLConn.Open();
> SqlDataAdapter adapter = new SqlDataAdapter(new
> SqlCommand("Select * from Orders", oSQLConn));
> DataSet ds=new DataSet();
> adapter.Fill(ds);
> DataView dv = ds.Tables[0].DefaultView;
> oSQLConn.Close();
> this.source.DataSource = dv;
> this.dataGridView1.DataSource = dv;
> this.manager = (CurrencyManager)this.BindingContext[dv];
> }
>
> private void dataGridView1_MouseClick(object sender, MouseEventArgs
> e)
> {
> findVaule = this.dataGridView1.CurrentCell.Value;
> }
>
> private void dataGridView1_Sorted(object sender, EventArgs e)
> {
> manager.Position = source.Find("orderID",
> Convert.ToInt32(findVaule));
> }
>
> 即需要处理MouseClick和Sorted事件。
>
>
> 郭轩
> 在线技术支持工程师
> 微软全球技术支持中心
> ---------------------------------------------------------------------------------------
> 我们的服务时间:周一至周五9:00-18:00(节假日除外)。我们将在两个工作日(48小时)内提供初始回应,并和您一起研究并解决问题。更多微软新闻组技术支持信息,请访问:http://support.microsoft.com/gp/newsgroupsupport/zh-cn.
>
> 回帖时,请在您的新闻组阅读器中使用“回复组(Reply to Group)”,这将帮助其他用户从您的提问中获益
> ---------------------------------------------------------------------------------------
> 本贴子以”现状”提供且没有任何担保,同时也没有授予任何权利。

t-xguo@prcvap.microsoft.com
04-11-2007, 07:43 AM
您好:

orderID是table Orders的主键,该段代码经测试没有问题。演示代码所用数据库安装文件可以从以下地址下载:http://www.microsoft.com/downloads/details.aspx?FamilyId=06616212-0356-46A0-8DA2-EEBC53A68034&displaylang=en
然后用Microsoft SQL Server Management Studio 执行以上安装文件的sql文件即可安装数据库。

郭轩
在线技术支持工程师
微软全球技术支持中心
---------------------------------------------------------------------------------------
我们的服务时间:周一至周五9:00-18:00(节假日除外)。我们将在两个工作日(48小时)内提供初始回应,并和您一起研究并解决问题。更多微软新闻组技术支持信息,请访问:http://support.microsoft.com/gp/newsgroupsupport/zh-cn.

回帖时,请在您的新闻组阅读器中使用“回复组(Reply to Group)”,这将帮助其他用户从您的提问中获益
---------------------------------------------------------------------------------------
本贴子以”现状”提供且没有任何担保,同时也没有授予任何权利。

t-xguo@prcvap.microsoft.com
04-13-2007, 03:05 AM
您好:

关于此主题,您是否还有疑问?如有任何疑问,欢迎在微软中文新闻组讨论。

郭轩
在线技术支持工程师
微软全球技术支持中心
---------------------------------------------------------------------------------------
我们的服务时间:周一至周五9:00-18:00(节假日除外)。我们将在两个工作日(48小时)内提供初始回应,并和您一起研究并解决问题。更多微软新闻组技术支持信息,请访问:http://support.microsoft.com/gp/newsgroupsupport/zh-cn.

回帖时,请在您的新闻组阅读器中使用“回复组(Reply to Group)”,这将帮助其他用户从您的提问中获益
---------------------------------------------------------------------------------------
本贴子以”现状”提供且没有任何担保,同时也没有授予任何权利。