473,796 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB DataGridView question

6 New Member
I have a datagridview that I am using for filling in the detail of an Invoice. So each row has Item, Quantity, Price.

I want to prevent the user from adding new rows if the Quantity and Price columns are not filled in.

Also when the user selects an Item (there is a combo fox on that column) I want to get the Price and fill in the Price column - what is the correct event to use for this?
Feb 11 '08 #1
3 1839
abev
22 New Member
I have a datagridview that I am using for filling in the detail of an Invoice. So each row has Item, Quantity, Price.

I want to prevent the user from adding new rows if the Quantity and Price columns are not filled in.

Also when the user selects an Item (there is a combo fox on that column) I want to get the Price and fill in the Price column - what is the correct event to use for this?
To prevent adding new rows you need to handle a focus event from the datagridview. First I would set Addnew = false for the gridview. Then set it to true after meeting your conditions.

Here's code I have that does something similar from the CellEnter event of the gridview:

Expand|Select|Wrap|Line Numbers
  1. Dim m_RowIndex As Integer = e.RowIndex
  2. If e.ColumnIndex = Me.InsertionOrderDetailDataGridView.Columns("NetCost").Index Then
  3.  
  4. If IsDBNull(InsertionOrderDetailDataGridView.Rows(m_RowIndex).Cells("CPM").Value) And _
  5.  
  6.                 If MsgBox("Calculate Net Cost?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Calculate?") = MsgBoxResult.Yes Then
  7.  
  8.                   'test the columns here
  9.  
  10.                 End If
  11.             End If
  12.  
The second part of your question I would handle the cell leave event of the gridview and calculate the value.

This should get you started :)
Feb 11 '08 #2
Gail248
6 New Member
The problem with setting Addnew = False is that is that this has to be done After they begin entering a new Row (and remains set like this until they complete it) but how do I determine (which event) that this has happened?

To prevent adding new rows you need to handle a focus event from the datagridview. First I would set Addnew = false for the gridview. Then set it to true after meeting your conditions.

Here's code I have that does something similar from the CellEnter event of the gridview:

Expand|Select|Wrap|Line Numbers
  1. Dim m_RowIndex As Integer = e.RowIndex
  2. If e.ColumnIndex = Me.InsertionOrderDetailDataGridView.Columns("NetCost").Index Then
  3.  
  4. If IsDBNull(InsertionOrderDetailDataGridView.Rows(m_RowIndex).Cells("CPM").Value) And _
  5.  
  6.                 If MsgBox("Calculate Net Cost?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Calculate?") = MsgBoxResult.Yes Then
  7.  
  8.                   'test the columns here
  9.  
  10.                 End If
  11.             End If
  12.  
The second part of your question I would handle the cell leave event of the gridview and calculate the value.

This should get you started :)
Feb 11 '08 #3
abev
22 New Member
The problem with setting Addnew = False is that is that this has to be done After they begin entering a new Row (and remains set like this until they complete it) but how do I determine (which event) that this has happened?
Ok gail that makes sense I read it too fast - let's see....

I assume we have some master info on the form then a detail (gridview) on the bottom? Not knowing all the details I can just throw out suggestions.

On form load if there are no rows in the detail then automatically add one. OR on gridview_enter if there are no rows you can add one.

After a row is added you can then set addnew = false. Check to be sure your fields are filled. If they are filled correctly on cellleave in the gridview, programatically add a new row.

This can get tricky because you probably have an indeterminate number of detail rows in the gridview and dont want to add rows willy nilly.

What I have done in a similar Master/detail app is to let users add rows to their hearts content, but do not let them save if they have not filled in the required rows in the gridview.

HTH ot least nudges you in a direction.
Feb 12 '08 #4

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

Similar topics

10
13360
by: milk-jam | last post by:
I'm trying to set my datagridview so that the first row will be left blank and to use it as a filtering filed for the datagridview. Until now I was using 2 datagridview the upper one with a header that sort and one row for filtering and the lower one with no header for the data. Only it is very complicated to work this way cause for example when the user click on sort on the upper datagridview I need to sort the lower grid and so on when...
0
6949
by: TNSFED | last post by:
I have a dilemma when trying to delete a row from the DataGridView. Here is a sample of my code: private void dgv_EQUPS_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { fDeleteRow = false; if (chx_DeleteFlag.Checked) {
7
12631
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's the background for my question... Before I switched my application over to the Fx 2.0, I used a DataGrid to display my data. I would store different DataGridTableStyles (each one with a custom set of columns) in the DataGrid.TableStyles property...
2
7823
by: michael sorens | last post by:
I have been trying to figure out how to use DataSets, BindingSources, DataGridViews, and XML together, but it is a challenge. I understand how to populate a DataGridView with XML basically as: DataSet ds = new DataSet(); ds.ReadXml(@"\usr\tmp\sample.xml"); dataGridView.DataSource = ds; dataGridView.DataMember = "targetElement"; What I found through experimentation is that the DataMember may specify
3
4656
by: Daniel Manes | last post by:
I need a strategy to debug this situation... I can't put all the code involved, but here are some of the critical lines with comments: ------------------------- Private _parentDataCell As DataGridViewCell 'declare private field _parentDataCell = _parentDataGrid.Rows(rowIndex).Cells(columnIndex) 'set to a specific cell Debug.Print(_parentDataCell.DataGridView.ToString) 'prints:
2
15533
by: Steve Richter | last post by:
what is the best way to use DataGridView to view data from large database tables? Where the sql select statement might return millions of rows? string connectionString = GetFinancesConnString(); string sqlSelect = "select CheckNbr, CheckDate, CheckAmt from Disbursements" ; SqlDataAdapter adapter = new SqlDataAdapter(sqlSelect, connectionString);
3
6331
by: =?Utf-8?B?Sm9obiBCdW5keQ==?= | last post by:
New to databinding in vs2005, I always did it manually in 2003. I have no problem loading comboboxes, and a change in that combobox changes the data in the textboxes but I can not figure out a way to get the data in a datagridview to change. For example 2 columns are ID and amount_paid, the datagridview loads on form load with all ID's and amounts. How do I get it to only bring back the selected ID. Sounds like I may need to change the SQL...
7
15663
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is there an equivalent property for the DataGridView? I have searched, but have not found one. I would like the user to be able to see all the columns of the table on one screen - thus eliminating the need to use the horizontal scroll bar to view...
1
7787
by: Karl | last post by:
Hi all... This is a good one. You'll like this... I am working on a course management tool that allows certain Courses to be cross referenced with Job Roles and, when they are, whether the course is a priority course or not. Simple. Because there is alot of data stored for each course, I am using a tab control with several pages. The Job Role cross-referencing comes on
6
2857
by: Miro | last post by:
Sorry for the cross post. I am stuck. I have a datagridview for poker rounds. Basically there are 3 columns in this datagridview. "Round" "SmallBlind" "BigBlind" I have an issue when I tab through the new row being added. It does not 'Add' that row, nor setup the 'next blank add row' so I can continue to tab
0
9685
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10244
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10201
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.