Hello,
I have a datagrid (dgr1) on a form and I'm trying to bind a currencyManager
Object (cma) to it and print the current row position. But all I get for
cma.Position is 0, 0, 0 for any row in dgr1. dgr1 populates correctly and
when I first set cma - it shows the correct number of rows in the table
(tbl1). In my case there are 14 rows for real, and that is what cma shows.
But when I click a row on dgr1 - cma.position just displays 0. cma is not
displaying the correct row number. Is there a property I need to set? Here
is the code I am using: dgr1 gets its data from Sql Server.
Dim conn As New SqlConnection, dA1, dA2 As SqlDataAdapter
Dim ds As New DataSet, dT1 As DataTable
Dim cmdSelTbl1 As SqlCommand, cma As CurrencyManager
------------------------------------------------------------------------------------
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String = "Server=winxp;UID=sa;PWD=;Database=dbContacts"
Try
conn.ConnectionString = strConn
cmdSelTbl1 = New SqlCommand
cmdSelTbl1.CommandType = CommandType.Text
cmdSelTbl1.CommandText = "Select * from tbl1"
cmdSelTbl1.Connection = conn
conn.Open()
dA1 = New SqlDataAdapter
dA1.SelectCommand = cmdSelTbl1
ds.Clear()
dA1.Fill(ds, "tbl1")
cma = CType(BindingContext(ds.Tables("tbl1")), CurrencyManager)
Console.WriteLine("cma.Count is " & cma.Count)
cma.Position = 0
dgr1.DataSource = ds
dgr1.DataMember = "tbl1"
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub dgr1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles dgr1.Click
Console.WriteLine(cma.Position)
End Sub
Is there some property I need to set my datagrid? How do I correctly bind
cma with the data Table?
Thanks,
Rich 2 3234
Hi,
"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com... Hello,
I have a datagrid (dgr1) on a form and I'm trying to bind a currencyManager Object (cma) to it and print the current row position. But all I get for cma.Position is 0, 0, 0 for any row in dgr1. dgr1 populates correctly and when I first set cma - it shows the correct number of rows in the table (tbl1). In my case there are 14 rows for real, and that is what cma shows. But when I click a row on dgr1 - cma.position just displays 0. cma is not displaying the correct row number. Is there a property I need to set? Here is the code I am using: dgr1 gets its data from Sql Server.
Dim conn As New SqlConnection, dA1, dA2 As SqlDataAdapter Dim ds As New DataSet, dT1 As DataTable Dim cmdSelTbl1 As SqlCommand, cma As CurrencyManager ------------------------------------------------------------------------------------ Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim strConn As String = "Server=winxp;UID=sa;PWD=;Database=dbContacts"
Try conn.ConnectionString = strConn cmdSelTbl1 = New SqlCommand cmdSelTbl1.CommandType = CommandType.Text cmdSelTbl1.CommandText = "Select * from tbl1" cmdSelTbl1.Connection = conn conn.Open() dA1 = New SqlDataAdapter dA1.SelectCommand = cmdSelTbl1 ds.Clear() dA1.Fill(ds, "tbl1") cma = CType(BindingContext(ds.Tables("tbl1")), CurrencyManager)
Try:
cma = CType(BindingContext(ds, "tbl1"), CurrencyManager )
I needs to be exactly like you bind the grid, using a DataSet and TableName,
see your binding code below.
HTH,
Greetings
Console.WriteLine("cma.Count is " & cma.Count) cma.Position = 0
dgr1.DataSource = ds dgr1.DataMember = "tbl1" Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub
Private Sub dgr1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgr1.Click Console.WriteLine(cma.Position) End Sub
Is there some property I need to set my datagrid? How do I correctly bind cma with the data Table?
Thanks, Rich
Thank you very much. That worked perfectly! I changed
dgr1.DataSource = ds
to
dgr1.DataSource = ds.Tables("tbl1")
Now currencymanager works fine.
Thanks for your help.
Rich
"Bart Mermuys" wrote: Hi,
"Rich" <Ri**@discussions.microsoft.com> wrote in message news:2F**********************************@microsof t.com... Hello,
I have a datagrid (dgr1) on a form and I'm trying to bind a currencyManager Object (cma) to it and print the current row position. But all I get for cma.Position is 0, 0, 0 for any row in dgr1. dgr1 populates correctly and when I first set cma - it shows the correct number of rows in the table (tbl1). In my case there are 14 rows for real, and that is what cma shows. But when I click a row on dgr1 - cma.position just displays 0. cma is not displaying the correct row number. Is there a property I need to set? Here is the code I am using: dgr1 gets its data from Sql Server.
Dim conn As New SqlConnection, dA1, dA2 As SqlDataAdapter Dim ds As New DataSet, dT1 As DataTable Dim cmdSelTbl1 As SqlCommand, cma As CurrencyManager ------------------------------------------------------------------------------------ Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim strConn As String = "Server=winxp;UID=sa;PWD=;Database=dbContacts"
Try conn.ConnectionString = strConn cmdSelTbl1 = New SqlCommand cmdSelTbl1.CommandType = CommandType.Text cmdSelTbl1.CommandText = "Select * from tbl1" cmdSelTbl1.Connection = conn conn.Open() dA1 = New SqlDataAdapter dA1.SelectCommand = cmdSelTbl1 ds.Clear() dA1.Fill(ds, "tbl1") cma = CType(BindingContext(ds.Tables("tbl1")), CurrencyManager)
Try: cma = CType(BindingContext(ds, "tbl1"), CurrencyManager )
I needs to be exactly like you bind the grid, using a DataSet and TableName, see your binding code below.
HTH, Greetings
Console.WriteLine("cma.Count is " & cma.Count) cma.Position = 0
dgr1.DataSource = ds dgr1.DataMember = "tbl1" Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub
Private Sub dgr1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgr1.Click Console.WriteLine(cma.Position) End Sub
Is there some property I need to set my datagrid? How do I correctly bind cma with the data Table?
Thanks, Rich This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ann Morris |
last post by:
INTRODUCTION
One of the most powerful aspects of .NET and Windows Forms is data
binding. Data binding is the process of associating user interface
(UI) elements with a data source to generate a...
|
by: Kevin |
last post by:
Hi Al
When I have a text box, list box, and a datagrid, how does a CurrencyManager relate to all these controls(seeing as though the datagrid uses Complex binding and textbox and list box use...
|
by: Pete Davis |
last post by:
I have written a custom databound grid control that we've been using
successfully for months, but one of our developers has just run into a
problem that I can't figure out.
The code for setting...
|
by: Kris Bethea via DotNetMonster.com |
last post by:
Greetings,
I have a VB.NET program that I am trying to convert to C# (my office
decided that we are going to use C# from now on).
I've only been working with C# for about a month now, so this...
|
by: Johann Blake |
last post by:
I've been playing around trying to bind textbox controls and datagrids
to typed datasets. Up until recently, I never used DataBindings. I
always manually wrote the value into a textbox and stored...
|
by: D |
last post by:
hi
I have a form with 2 datagrids showing related table data in a master /
child or order / order details type relationship. I would like to auto
select the row in the order details table which...
|
by: Jeremy |
last post by:
I have a dataset containing 2 tables. A is the master table, B is a lookup
table. There is a combobox bound to B, which updates a value in a FK field
in A.
my currencymanager is created thus:...
|
by: Johnny Liner |
last post by:
Hello...
I am creating a CurrencyManager object and setting it like this ...
Code:
Dim cm as CurrencyManager
(...)
'On Open event of form
cm = Me.BindingContext(ds,"tblPersonData")
|
by: Rich |
last post by:
Hello,
Following an example at
http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken Tucker)
on binding a dataRelation to a Datagridview for sqlClient, I was able to
view rows...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |