选定的索引改变了组合框 [英] Selected index changed combobox

查看:57
本文介绍了选定的索引改变了组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两种情况:

1)我从组合框中添加新记录和选择ISBN。 SelectedIndexChanged应该从DataBase触发并填充BookName。它工作正常。



2)在Form中初始加载所有数据后,当我从Record 1导航到Record 2等时,SelectedIndexChanged将激活并填充BookName。数据库。但是,这是不可取的。



如何识别和区分新记录与获取记录,根据这些记录控制这些操作?



我尝试了什么:



Two situations:
1) I add a new record and Select ISBN from the combobox. SelectedIndexChanged should fire and populate the BookName from the DataBase. It works and fine.

2) After initial loading of all data in Form, when I navigate from Record 1 to Record 2 etc, SelectedIndexChanged fires and populates BookName from the DataBase. But, this is not desirable.

How to identify and distinguish New Record from the Fetched Record, based on which these actions be controlled?

What I have tried:

Private Sub ISBNComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ISBNComboBox.SelectedIndexChanged
        Dim lISBN As String
        lISBN = ISBNComboBox.Text
        PopulateBookName() 'When ISBN is changed, Book Title should be updated
    End Sub

推荐答案

您需要向我们展示您的 PopulateBookName()方法是如何做的。从本质上讲,您只需更新SQL查询即可获得最新记录:



You need to show us how your PopulateBookName() method was doing. Essentially, you just need to update your SQL query to get the latest record by doing either:

SELECT TOP 1 * FROM [TABLENAME] ORDER BY id DESC





您还可以使用发布日期获取最新记录。这实际上取决于你。



You can also use the Posted Date to get the latest record. That really depends on you.


Book Name是一个依赖字段。根据ISBN号,填写书名。这就是全部。



问题是:当我添加新记录时,根据ISBN,将填写书名。

但是,当我查询DataBase中的现有记录时,获取的ISBN应该触发SelectedIndexChanged过程,并且不应填充Book Name。否则,它将记录标记为已编辑的记录,并提示保存。
Book Name is a dependent field. Based on ISBN number, book name is populated. That is all.

The issue is: When I add NEW Records, based on the ISBN, Book name is to be populated.
But, when I QUERY the existing records from the DataBase, the fetched ISBN should trigger the SelectedIndexChanged procedure and should not populate the Book Name. Otherwise, it marks the record as edited record, and prompts for saving.


这篇关于选定的索引改变了组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆