PC Review


Reply
Thread Tools Rate Thread

Datagrid Current Position

 
 
No_So_Clever
Guest
Posts: n/a
 
      8th Nov 2005
Hi there,

I have th following Code to Get my Current Position and show it in a text
box, as "Record 1 of 129" for Example.

>> Me.lblNavLocation.Text = (((cmSystemUsers.Position + 1).ToString + " of

") + cmSystemUsers.Count.ToString) <<

I have a Datagrid on my Winform, When I click on one of the rows in My
datagrid I would like it to to indicate which record it is on e.g "Record 1
or 129", "Record 54 or 129", etc, etc, but it dosn`t update my
lblNavLocation.Text. How would I get it to update whn I click on a row in my
datagrid?

Many Kind Thanks in Avance
Regards
NSC


 
Reply With Quote
 
 
 
 
S.M. Altaf [MVP]
Guest
Posts: n/a
 
      8th Nov 2005
Me.Label1.Text = Me.DataGrid1.CurrentRowIndex.ToString() & " of " &
CType(Me.DataGrid1.DataSource, DataTable).Rows.Count - 1

--------------------------------------------------------------------------------
All that glitters has a high refractive index.
www.mendhak.com


"No_So_Clever" <(E-Mail Removed)> wrote in message
news:FP-(E-Mail Removed)...
> Hi there,
>
> I have th following Code to Get my Current Position and show it in a text
> box, as "Record 1 of 129" for Example.
>
> >> Me.lblNavLocation.Text = (((cmSystemUsers.Position + 1).ToString + " of

> ") + cmSystemUsers.Count.ToString) <<
>
> I have a Datagrid on my Winform, When I click on one of the rows in My
> datagrid I would like it to to indicate which record it is on e.g "Record
> 1 or 129", "Record 54 or 129", etc, etc, but it dosn`t update my
> lblNavLocation.Text. How would I get it to update whn I click on a row in
> my datagrid?
>
> Many Kind Thanks in Avance
> Regards
> NSC
>



 
Reply With Quote
 
No_So_Clever
Guest
Posts: n/a
 
      8th Nov 2005
Hi there,

Thanks for you reply.
Im getting errors on: CType(Me.DataGrid1.DataSource, DataTable).

I take it I change this to CType(me.dgdSystemUsers.dsSystemUsers, Passwords)

dgdSystemUsers been my DataGrid, dsSysetmUsers been my DataSet and Passwords
been my tabel. Is that right?

Many Thanks
Cheers
NSC

"S.M. Altaf [MVP]" <(E-Mail Removed)> wrote in message
news:%23hed%(E-Mail Removed)...
> Me.Label1.Text = Me.DataGrid1.CurrentRowIndex.ToString() & " of " &
> CType(Me.DataGrid1.DataSource, DataTable).Rows.Count - 1
>
> --------------------------------------------------------------------------------
> All that glitters has a high refractive index.
> www.mendhak.com
>
>
> "No_So_Clever" <(E-Mail Removed)> wrote in message
> news:FP-(E-Mail Removed)...
>> Hi there,
>>
>> I have th following Code to Get my Current Position and show it in a text
>> box, as "Record 1 of 129" for Example.
>>
>> >> Me.lblNavLocation.Text = (((cmSystemUsers.Position + 1).ToString + "
>> >> of

>> ") + cmSystemUsers.Count.ToString) <<
>>
>> I have a Datagrid on my Winform, When I click on one of the rows in My
>> datagrid I would like it to to indicate which record it is on e.g "Record
>> 1 or 129", "Record 54 or 129", etc, etc, but it dosn`t update my
>> lblNavLocation.Text. How would I get it to update whn I click on a row in
>> my datagrid?
>>
>> Many Kind Thanks in Avance
>> Regards
>> NSC
>>

>
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      8th Nov 2005
Hi,

Have a look of the currencymanager which mostly works the nices for this
kind of problems.

I changed it a little bit, so it should fits your prolbem now.

http://www.vb-tips.com/default.aspx?...f-587f730fa118

I hope this helps,

Cor


 
Reply With Quote
 
Wizard
Guest
Posts: n/a
 
      8th Nov 2005
Hi Cor,

Im Totally Confused now, why Currency Manager? I`ve been looking on the net
and it seems i need to use DataGrid1.CurrentCellChanged also some place say
use Dataviews. I don`t mean to knock you or your knowlage, or anything like
that as im sure you know more than a mear newbie like myself but im just
getting a little confused with everything at the moment

I can understand looking at the DataGrid1.CurrentCellChanged but i can`t see
anything on how to call it, or even any real coding for it which would work
in my Mini App.

Hope you can help.
Many Thanks
NSC

"Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
news:ugA%(E-Mail Removed)...
> Hi,
>
> Have a look of the currencymanager which mostly works the nices for this
> kind of problems.
>
> I changed it a little bit, so it should fits your prolbem now.
>
> http://www.vb-tips.com/default.aspx?...f-587f730fa118
>
> I hope this helps,
>
> Cor
>
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      8th Nov 2005
Wizard,

My expirience is that this one works on places where the ones you name don't
work.

You can by the way that one as well use with the datatview inside the
datatable.

Than the datasource becomes dt.defaultview and the setting to cma as well
dt.defaultview. (What I prefer, however I had written simple so I kept it as
simple as possible).

So try it and you see how easy it is in use.

:-)

Cor


 
Reply With Quote
 
No_So_Clever
Guest
Posts: n/a
 
      9th Nov 2005
Hi Cor,

Sorry Now im really confused. How do I use this example on my project? You
example dosn`t even have a datagrid on it
Ive found this code that i`ve been playing with, but this on`t work either,
searching the net for Datagrid, Textbox Binding with Currency Manager dosn`t
throw me much help either
I could post my full code if that would help?:
Would it help of shold i use your example? Only thing with the example below
is I don`t know how to call it I mean it sits there, but what triggers it
when i click on a Row in my datagrid?

Private Sub dgdSystemUsers_CurrentCellChanged(ByVal sender As System.Object,
ByVal ne As System.Windows.Forms.NavigateEventArgs)
'Get the row number on the DataGrid
Dim iRownr As Integer = Me.dgdSystemUsers.CurrentCell.RowNumber
'Get the column number on the DataGrid
Dim iColnr As Integer = Me.dgdSystemUsers.CurrentCell.ColumnNumber
'Get the content of the cell in the clicked cell on the Datagrid
Dim cellvalue1 As Object = Me.dgdSystemUsers(iRownr, iColnr)
'Get the next cell content in the same row
Dim cellvalue2 As Object = Nothing
Try
cellvalue2 = Me.dgdSystemUsers(iRownr, iColnr + 1)
'Display (cellvalue1+cellvalue2) in TextBox "textBox1"
Me.lblNavLocation.Text = cellvalue1.ToString() + " " + cellvalue2.ToString()
Catch ex As Exception
'The exception occurs here because we increment iColnr+1
'Delete or comment MessageBox.Show-line you won´t get the error message
MessageBox.Show("No further columns after the last column-->> " +
ex.Message, "STOP")
cellvalue2 = Me.dgdSystemUsers(iRownr, iColnr - 1)
'Display this time (cellvalue2+cellvalue1) in TextBox
Me.lblNavLocation.Text = cellvalue2.ToString() + " " + cellvalue1.ToString()
End Try
End Sub

Many Thanks
NSC


"Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Wizard,
>
> My expirience is that this one works on places where the ones you name
> don't work.
>
> You can by the way that one as well use with the datatview inside the
> datatable.
>
> Than the datasource becomes dt.defaultview and the setting to cma as well
> dt.defaultview. (What I prefer, however I had written simple so I kept it
> as simple as possible).
>
> So try it and you see how easy it is in use.
>
> :-)
>
> Cor
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      9th Nov 2005
No so clever,

Create a new project.
Drag a datagrid on the form
Drag 3 textboxes on the form
Go go the code
Paste in the code from the webpage
change at the error that you than sees datagridview in datagrid
at the 4 other ones you change label in textbox
start debug run

You will see in textbox 3 all the time the current row possition.

This should run and use less code than you are using now.

Cor

"No_So_Clever" <(E-Mail Removed)> schreef in bericht
news:4b-(E-Mail Removed)...
> Hi Cor,
>
> Sorry Now im really confused. How do I use this example on my project? You
> example dosn`t even have a datagrid on it
> Ive found this code that i`ve been playing with, but this on`t work
> either, searching the net for Datagrid, Textbox Binding with Currency
> Manager dosn`t throw me much help either
> I could post my full code if that would help?:
> Would it help of shold i use your example? Only thing with the example
> below is I don`t know how to call it I mean it sits there, but what
> triggers it when i click on a Row in my datagrid?
>
> Private Sub dgdSystemUsers_CurrentCellChanged(ByVal sender As
> System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs)
> 'Get the row number on the DataGrid
> Dim iRownr As Integer = Me.dgdSystemUsers.CurrentCell.RowNumber
> 'Get the column number on the DataGrid
> Dim iColnr As Integer = Me.dgdSystemUsers.CurrentCell.ColumnNumber
> 'Get the content of the cell in the clicked cell on the Datagrid
> Dim cellvalue1 As Object = Me.dgdSystemUsers(iRownr, iColnr)
> 'Get the next cell content in the same row
> Dim cellvalue2 As Object = Nothing
> Try
> cellvalue2 = Me.dgdSystemUsers(iRownr, iColnr + 1)
> 'Display (cellvalue1+cellvalue2) in TextBox "textBox1"
> Me.lblNavLocation.Text = cellvalue1.ToString() + " " +
> cellvalue2.ToString()
> Catch ex As Exception
> 'The exception occurs here because we increment iColnr+1
> 'Delete or comment MessageBox.Show-line you won´t get the error message
> MessageBox.Show("No further columns after the last column-->> " +
> ex.Message, "STOP")
> cellvalue2 = Me.dgdSystemUsers(iRownr, iColnr - 1)
> 'Display this time (cellvalue2+cellvalue1) in TextBox
> Me.lblNavLocation.Text = cellvalue2.ToString() + " " +
> cellvalue1.ToString()
> End Try
> End Sub
>
> Many Thanks
> NSC
>
>
> "Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Wizard,
>>
>> My expirience is that this one works on places where the ones you name
>> don't work.
>>
>> You can by the way that one as well use with the datatview inside the
>> datatable.
>>
>> Than the datasource becomes dt.defaultview and the setting to cma as well
>> dt.defaultview. (What I prefer, however I had written simple so I kept it
>> as simple as possible).
>>
>> So try it and you see how easy it is in use.
>>
>> :-)
>>
>> Cor
>>

>
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      9th Nov 2005
Than to make it complete for if somebody wants to sort.

make from the two time dt on the page dt.defaultview
DataGrid1.DataSource = dt.defaultview
Dim cma As CurrencyManager = DirectCast(BindingContext(dt.defaultview),
CurrencyManager)

Cor

"No_So_Clever" <(E-Mail Removed)> schreef in bericht
news:4b-(E-Mail Removed)...
> Hi Cor,
>
> Sorry Now im really confused. How do I use this example on my project? You
> example dosn`t even have a datagrid on it
> Ive found this code that i`ve been playing with, but this on`t work
> either, searching the net for Datagrid, Textbox Binding with Currency
> Manager dosn`t throw me much help either
> I could post my full code if that would help?:
> Would it help of shold i use your example? Only thing with the example
> below is I don`t know how to call it I mean it sits there, but what
> triggers it when i click on a Row in my datagrid?
>
> Private Sub dgdSystemUsers_CurrentCellChanged(ByVal sender As
> System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs)
> 'Get the row number on the DataGrid
> Dim iRownr As Integer = Me.dgdSystemUsers.CurrentCell.RowNumber
> 'Get the column number on the DataGrid
> Dim iColnr As Integer = Me.dgdSystemUsers.CurrentCell.ColumnNumber
> 'Get the content of the cell in the clicked cell on the Datagrid
> Dim cellvalue1 As Object = Me.dgdSystemUsers(iRownr, iColnr)
> 'Get the next cell content in the same row
> Dim cellvalue2 As Object = Nothing
> Try
> cellvalue2 = Me.dgdSystemUsers(iRownr, iColnr + 1)
> 'Display (cellvalue1+cellvalue2) in TextBox "textBox1"
> Me.lblNavLocation.Text = cellvalue1.ToString() + " " +
> cellvalue2.ToString()
> Catch ex As Exception
> 'The exception occurs here because we increment iColnr+1
> 'Delete or comment MessageBox.Show-line you won´t get the error message
> MessageBox.Show("No further columns after the last column-->> " +
> ex.Message, "STOP")
> cellvalue2 = Me.dgdSystemUsers(iRownr, iColnr - 1)
> 'Display this time (cellvalue2+cellvalue1) in TextBox
> Me.lblNavLocation.Text = cellvalue2.ToString() + " " +
> cellvalue1.ToString()
> End Try
> End Sub
>
> Many Thanks
> NSC
>
>
> "Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Wizard,
>>
>> My expirience is that this one works on places where the ones you name
>> don't work.
>>
>> You can by the way that one as well use with the datatview inside the
>> datatable.
>>
>> Than the datasource becomes dt.defaultview and the setting to cma as well
>> dt.defaultview. (What I prefer, however I had written simple so I kept it
>> as simple as possible).
>>
>> So try it and you see how easy it is in use.
>>
>> :-)
>>
>> Cor
>>

>
>



 
Reply With Quote
 
No_So_Clever
Guest
Posts: n/a
 
      9th Nov 2005
Hi Cor,

Excellent - Got you Eample Working)) Cheers Mate.

OK So in My Project I need to Add:

(I already have the following in my project) Dim WithEvents cmSystemUsers As
CurrencyManager

So Change:

Dim cma As CurrencyManager = DirectCast(BindingContext(dt), CurrencyManager)
To:

cmSystemUsers.DirectCast(BindingContext(dt), CurrencyManager) (What would go
in the Place of (DT) would this be my Dataset? i.e dsSystemUsers?

Then add: AddHandler cma.CurrentChanged, AddressOf CurrentChanged - into my
Forms Load

How would I change: Label3.Text = DirectCast(sender,
CurrencyManager).Position.ToString

To be the Equivilant of : Me.lblNavLocation.Text = (((cmSystemUsers.Position
+ 1).ToString + " of ") + cmSystemUsers.Count.ToString)

Many Thanks Again
NSC

"Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> No so clever,
>
> Create a new project.
> Drag a datagrid on the form
> Drag 3 textboxes on the form
> Go go the code
> Paste in the code from the webpage
> change at the error that you than sees datagridview in datagrid
> at the 4 other ones you change label in textbox
> start debug run
>
> You will see in textbox 3 all the time the current row possition.
>
> This should run and use less code than you are using now.
>
> Cor
>
> "No_So_Clever" <(E-Mail Removed)> schreef in bericht
> news:4b-(E-Mail Removed)...
>> Hi Cor,
>>
>> Sorry Now im really confused. How do I use this example on my project?
>> You example dosn`t even have a datagrid on it
>> Ive found this code that i`ve been playing with, but this on`t work
>> either, searching the net for Datagrid, Textbox Binding with Currency
>> Manager dosn`t throw me much help either
>> I could post my full code if that would help?:
>> Would it help of shold i use your example? Only thing with the example
>> below is I don`t know how to call it I mean it sits there, but what
>> triggers it when i click on a Row in my datagrid?
>>
>> Private Sub dgdSystemUsers_CurrentCellChanged(ByVal sender As
>> System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs)
>> 'Get the row number on the DataGrid
>> Dim iRownr As Integer = Me.dgdSystemUsers.CurrentCell.RowNumber
>> 'Get the column number on the DataGrid
>> Dim iColnr As Integer = Me.dgdSystemUsers.CurrentCell.ColumnNumber
>> 'Get the content of the cell in the clicked cell on the Datagrid
>> Dim cellvalue1 As Object = Me.dgdSystemUsers(iRownr, iColnr)
>> 'Get the next cell content in the same row
>> Dim cellvalue2 As Object = Nothing
>> Try
>> cellvalue2 = Me.dgdSystemUsers(iRownr, iColnr + 1)
>> 'Display (cellvalue1+cellvalue2) in TextBox "textBox1"
>> Me.lblNavLocation.Text = cellvalue1.ToString() + " " +
>> cellvalue2.ToString()
>> Catch ex As Exception
>> 'The exception occurs here because we increment iColnr+1
>> 'Delete or comment MessageBox.Show-line you won´t get the error message
>> MessageBox.Show("No further columns after the last column-->> " +
>> ex.Message, "STOP")
>> cellvalue2 = Me.dgdSystemUsers(iRownr, iColnr - 1)
>> 'Display this time (cellvalue2+cellvalue1) in TextBox
>> Me.lblNavLocation.Text = cellvalue2.ToString() + " " +
>> cellvalue1.ToString()
>> End Try
>> End Sub
>>
>> Many Thanks
>> NSC
>>
>>
>> "Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Wizard,
>>>
>>> My expirience is that this one works on places where the ones you name
>>> don't work.
>>>
>>> You can by the way that one as well use with the datatview inside the
>>> datatable.
>>>
>>> Than the datasource becomes dt.defaultview and the setting to cma as
>>> well dt.defaultview. (What I prefer, however I had written simple so I
>>> kept it as simple as possible).
>>>
>>> So try it and you see how easy it is in use.
>>>
>>> :-)
>>>
>>> Cor
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the current cell position in VBA (eq. Row(), col() in F =?Utf-8?B?Sm9oYW4yMDAw?= Microsoft Excel Programming 3 6th Oct 2010 12:54 AM
Current cell position =?Utf-8?B?QUpQZW5kcmFnb24=?= Microsoft Excel Worksheet Functions 1 3rd Feb 2006 04:28 PM
Current Caret Position =?Utf-8?B?SHVnaA==?= Microsoft ASP .NET 1 5th Feb 2004 01:57 PM
ADO.NET - Current Position Dave Microsoft ADO .NET 6 13th Jan 2004 02:02 AM
get current position in textbox gie Microsoft Dot NET Compact Framework 3 9th Nov 2003 02:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:59 AM.