我有一个鼠标点击事件处理函数,当我选择第一个时间,但它的工作原理..?它的、第一个、当我、我有一个

由网友(心中有梦闯天下)分享简介:我有一个的DataGridView 在C#这是我的Access数据库连接。我看到我的的DataGridView 所有的书。我创建了一个鼠标点击事件处理程序选择行比我能保存该行,当你看到如下:I have a DataGridView in C# which is connected with my Access da...

我有一个的DataGridView 在C#这是我的Access数据库连接。我看到我的的DataGridView 所有的书。我创建了一个鼠标点击事件处理程序选择行比我能保存该行,当你看到如下:

I have a DataGridView in C# which is connected with my Access database. I see all the books on my DataGridView. I have created a mouse Click event handler to select a row than I can save that row, as you see below:

private void Mouse_Click(object sender, MouseEventArgs e)
{
    try
    {
        temp = dataGridView1.SelectedRows[0].Index.ToSt… 

        //This one is selecting the row. To do that select panel>event> on MouseClick write name and double click:

        MessageBox.Show("You have selected the row " + temp);
    }
    catch
    {
    }
}

它的工作原理,当我打开窗体。然而,当我选定行保存到另一个数据库,鼠标点击事件处理程序停止工作。换句话说,储蓄选择的第一行,以后我回来的时候选择其他行并保存到数据库中的鼠标点击事件处理程序不起作用。有消息称行超出了范围。

It works when I open the form. However, after I save the selected row to another database, the Mouse Click event handler stop working. In other words, after saving the first selected row, when I come back to select another row and save to database the Mouse Click Event handler does not work. The Message says row is out of range.

推荐答案

您没有给出相关的连接类型,事件处理程序,更重要的是你保存/更新记录的方式,所以我只是猜测这里太多的信息:你不小心覆盖网格的数据源?那是我唯一能想象这样的行为(行超出范围 - 这也假设事件仍会按预期工作,但code的功能不能看到数据了)。

You didn't give too much information related to connection type, Event Handler and more importantly the way you save/update the record so I'm just guessing here: aren't you accidentally overwriting the DataSource of your grid? That's the only thing I can imagine for such behavior ("row is out of range" - which also assumes the event still works as intended but the code in the function cannot see the data anymore).

阅读全文

相关推荐

最新文章