none
AbsolutePosition in a dataset in vb.net 2017 RRS feed

  • Question

  • my Form is based on a dataset

    I want to be able to display the current postion in a text box

    How can I do this?


    • Edited by Moshe Singer Thursday, February 22, 2018 6:17 PM
    Thursday, February 22, 2018 6:14 PM

Answers

  • One way is to use a BindingSource, set it's DataSource to the DataSet. Set the BindingSource to a DataGridView or other controls.

    Place a BindingNavigator on the form, remove all controls except the text box for which shows the postion and undock the Navigator.

    Or use a BindingSource w/o a BindingNavigator, in the Position changed event get the BindingSource position, assign it to a label or text box.

    A quickie example showing the position at the bottom of the screen


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Moshe Singer Sunday, March 11, 2018 7:10 PM
    Thursday, February 22, 2018 6:44 PM
    Moderator

All replies

  • One way is to use a BindingSource, set it's DataSource to the DataSet. Set the BindingSource to a DataGridView or other controls.

    Place a BindingNavigator on the form, remove all controls except the text box for which shows the postion and undock the Navigator.

    Or use a BindingSource w/o a BindingNavigator, in the Position changed event get the BindingSource position, assign it to a label or text box.

    A quickie example showing the position at the bottom of the screen


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Moshe Singer Sunday, March 11, 2018 7:10 PM
    Thursday, February 22, 2018 6:44 PM
    Moderator
  • The dataset has no current position, it is a kind of wrapper around datatables 

    However for a table, there are 2 ways, with the bindinglist the property position gives the row and with the databinding class you can use the currencymanager with the same named property. 

    Look for the later on our website 

    http://www.vb-tips.com/CurrencyManager.aspx

    Be aware in this example are the most rows for the presentation.


    Success
    Cor

    Thursday, February 22, 2018 6:49 PM
  • Hi,

    If you display data with using DataGridView, you can use CurrentCellChanged event and get Row/Column index.
         
    Private Sub DataGridView_CurrentCellChanged(sender As Object, e As EventArgs) Handles DataGridView.CurrentCellChanged
    	Me.RowIndex.Text = Me.DataGridView.CurrentCell.RowIndex + 1
    	Me.ColIndex.Text = Me.DataGridView.CurrentCell.ColumnIndex + 1
    End Sub

    Regards,

    Ashidacchi

    Thursday, February 22, 2018 11:46 PM
  • Hi,

    I'm not certain if I can understand correctly your question.
    I'm wondering if "the current position" means location of mouse pointer. Would you specify the meaning of it?  

    Regards,

    Ashidacchi

    Thursday, February 22, 2018 11:55 PM
  • Okay, had some time to play with this. 

    The following is the result where I loaded a customer DataGridView (below) with a DataTable. This works with a data set to as you will be setting the data source of the DataGridView with a table out of the data set.

    Set the data source

    DataGridViewWithRowIndexer1.DataSource = dt

    I have that DataGridView, a label and text box, the TextBox is data bound to a custom property Indexer (feel free to rename it)

    TextBox1.DataBindings.Add("Text", DataGridViewWithRowIndexer1, "Indexer")

    Here is the custom DataGridView

    Imports System.ComponentModel
    Imports System.Runtime.CompilerServices
    
    Public Class DataGridViewWithRowIndexer
        Inherits DataGridView
        Implements INotifyPropertyChanged
    
        Public Sub New()
        End Sub
    
        Private _indexer As Integer
        Public Event PropertyChanged As PropertyChangedEventHandler _
            Implements INotifyPropertyChanged.PropertyChanged
        Private Sub NotifyPropertyChanged(
            <CallerMemberName()>
            Optional ByVal propertyName As String = Nothing)
    
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    
        End Sub
        ''' <summary>
        ''' Returns the current row index which is zero based
        ''' </summary>
        ''' <returns></returns>
        Public Property Indexer() As Integer
            Get
                Return _indexer
            End Get
            Set
                _indexer = Value
            End Set
        End Property
        Protected Overrides Sub OnRowEnter(e As DataGridViewCellEventArgs)
    
            _indexer = e.RowIndex
    
            NotifyPropertyChanged("Indexer")
    
            MyBase.OnRowEnter(e)
    
        End Sub
    End Class

    I implement INotifyPropertyChanged for the Indexer property and set it on OnRowEnter event (overrode it), call the notification property changed on Indexer which is set via _indexer then call the base OnRowEnter event.

    The key in the notification changed is caller information.

    Usage: Add the customer DataGridView to your project, build. Now replace the current DataGridView with the new one which will now be in your toolbox.

    Hope this is of assistance :-)


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, February 23, 2018 12:51 AM
    Moderator