473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I disable a button if First Row of DataGridView selected ?

Hi all,

I want be able to enable and disable navigation buttons when on the first or
last row of a DataGridView object.

I have a populated DataGridView and two buttons - "First Row" and "Previous Row".
If the user clicks "First Row", they are taken to the first row in the DataGridView via:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnFirstRecord_Click(...) 
  2. ' Move to first record in job list 
  3. dgvMyRecords.CurrentCell = dgvMyRecords.Rows(0).Cells(0)
  4. End Sub
What I then want to to is disable the Prev Row button like this...

Expand|Select|Wrap|Line Numbers
  1. Private Sub dgvMyRecords_SelectionChanged(...)
  2. If dgvMyRecords.CurrentRow.Index = 0 Then 
  3. btnPrevRow.Enabled = False
  4. Else 
  5. btnPrevRow.Enabled = True 
  6. End if 
  7. End Sub
The problem is... this works if the user selects the first record using the mouse,
but not if the first record is selected through the code using CurrentCell.

If I click on the first row, SelectionChanged gets called AFTER the row gets changed.
If I set dgvMyRecords.CurrentCell to dgvMyRecords.Rows(0).Cells(0) (ie. select the first row via code), SelectionChanged gets called, but BEFORE the row gets changed !?!?!?

Can anyone show me how to do this ?

cheers,
Matt.
Jul 9 '07 #1
0 2220

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
1
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
0
by: Bob | last post by:
Loading data in a datagridview control in Vs2005, Vb.Net. If data is loaded in control I need first record shown to be automatically the selected record. By defaukt it is not considered selected,...
1
by: Mike P | last post by:
How do you disable the edit button for selected rows in a gridview? Here is my button : <asp:CommandField ShowEditButton="True" ButtonType="Link" ShowCancelButton="True" UpdateText="Update"...
2
by: =?Utf-8?B?RGlvZ28gQWx2ZXMgLSBTb2Z0d2FyZSBEZXZlbG9w | last post by:
greetings, I have a datagrid view filled with some data, in that data some of the cells are null and I would like to not let the user select the rows with null values... the problem is that...
1
by: Paul Schwann | last post by:
Hi Group, I am using C# with .NET 2.0 and Visual Studio 2005. I have a GUI with a DataGridView (DGV) and a BindingSource for the data. The data are added programmatically, up to 5 rows per...
1
by: Andrus | last post by:
I have Text box controls and DataGridView control in WinForms form. DataGridview contains custom ComboBox columns and standard TextBox columns. Edit mode is EditOnEnter. When focus is moved...
0
by: Christian | last post by:
hi, i create a windos application with c#2008 and i have a datagridview... when it start, there is a selected rows; i whant to disable this!
5
by: bill | last post by:
When you retrieve records to diplay in a DataGridView control the first record has the background highlighted even though no row is yet selected. Does anyone know a way to suppress this first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
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...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.