Friday, July 5, 2013

Datagridview Cellvaluechanged Event VB.net


DatagridView is a windows forms grid Control . It was first introduced in 
.Net framework 1.0and It comes with advanced and improved features in .Net Framework 2.0  It allows you to show the data in the tabular form. It contains data organized in rows and columns. It can be used to retrieve data in Tabular from from Database . It can be bound to Sql Database or Microsoft-Access Database.


Datagridview Cellvaluechanged Event in VB.net is used to make the change to occur or to call an event when value within particular cell is changed. In this app I have put event on each . when value of cell is changed its corresponding value in Maskedtextbox will change



Download Datagridview cellvaluechanged App



Design For Datagridview Cellvaluechanged Event VB.net


-- Add DatagridView To Form


1. Click on Tools


2. Then Scroll down and Find Datagridview .






3. Now Double click on it to put it on windows form.




-- Add Columns To Datagridview

1. Single Click on Datagridview


2. Click on small arrow on Top-right of Datagridview


3. A pop-up Menu appears. Click on "Add Column"





4. Now in Add Column Dialog Box Change HeaderText to "Name" and Click on Add . This Adds column Name to Datagridview


5. Now in second column give HeaderText to "Salary"


6. Now in Third column give HeaderText to "Bonus"


7. Now in Fourth column give HeaderText to "Total Salary"


8. Now Add Four Labels to Form and change its text property to :-


( I ) Name

( II ) Salary
( III )Bonus
( IV )Total Salary

9. Take four Masked Textbox from Toolbox and drag them to Windows form






10. Take a Button and Change its Text Property to "Get Data".





How To Operate


1 click on Get Data Button


2. It will load Default data in datagridview


3. If you change data in any Datagridview column Then the corresponding value in MaskedTextbox also change




Code For Datagridview 


Cellvaluechanged Event vb.net App


Public Class Form5 Public isdirty As Boolean Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DataGridView1.Rows(0).Cells(0).Value = "Jorge" DataGridView1.Rows(0).Cells(1).Value = 12000 DataGridView1.Rows(0).Cells(2).Value = 2900 DataGridView1.Rows(0).Cells(3).Value = DataGridView1.Rows(0).Cells(1).Value + DataGridView1.Rows(0).Cells(2).Value End Sub Private Sub MaskedTextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MaskedTextBox1.TextChanged DataGridView1.Rows(0).Cells(0).Value = MaskedTextBox1.Text End Sub Private Sub MaskedTextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MaskedTextBox2.TextChanged DataGridView1.Rows(0).Cells(1).Value = MaskedTextBox2.Text DataGridView1.Rows(0).Cells(3).Value = Val(DataGridView1.Rows(0).Cells(1).Value) + Val(DataGridView1.Rows(0).Cells(2).Value) End Sub Private Sub MaskedTextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MaskedTextBox3.TextChanged DataGridView1.Rows(0).Cells(2).Value = MaskedTextBox3.Text DataGridView1.Rows(0).Cells(3).Value = Val(DataGridView1.Rows(0).Cells(1).Value) + Val(DataGridView1.Rows(0).Cells(2).Value) End Sub Private Sub MaskedTextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MaskedTextBox4.TextChanged DataGridView1.Rows(0).Cells(3).Value = MaskedTextBox4.Text DataGridView1.Rows(0).Cells(3).Value = Val(DataGridView1.Rows(0).Cells(1).Value) + Val(DataGridView1.Rows(0).Cells(2).Value) End Sub Private Sub EndEdit(ByVal sender As System.Object, ByVal e As EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged If DataGridView1.IsCurrentCellDirty Then DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit) End If End Sub Private Sub DataGridView1_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged If e.RowIndex = -1 Then isdirty = True End If If e.ColumnIndex = 0 Then MaskedTextBox1.Text = DataGridView1.Rows(0).Cells(0).Value End If If e.ColumnIndex = 1 Then MaskedTextBox2.Text = DataGridView1.Rows(0).Cells(1).Value DataGridView1.Rows(0).Cells(3).Value = Val(DataGridView1.Rows(0).Cells(1).Value) + Val(DataGridView1.Rows(0).Cells(2).Value) End If If e.ColumnIndex = 2 Then MaskedTextBox3.Text = DataGridView1.Rows(0).Cells(2).Value DataGridView1.Rows(0).Cells(3).Value = Val(DataGridView1.Rows(0).Cells(1).Value) + Val(DataGridView1.Rows(0).Cells(2).Value) End If If e.ColumnIndex = 3 Then MaskedTextBox4.Text = DataGridView1.Rows(0).Cells(3).Value Dim c As Integer = DataGridView1.Rows(0).Cells(3).Value Dim str As String = CInt(c) If Len(str) = 1 Then MaskedTextBox4.Mask = "0" ElseIf Len(str) = 2 Then MaskedTextBox4.Mask = "00" ElseIf Len(str) = 3 Then MaskedTextBox4.Mask = "0,00" ElseIf Len(str) = 4 Then MaskedTextBox4.Mask = "0,000" ElseIf Len(str) = 5 Then MaskedTextBox4.Mask = "00,000" ElseIf Len(str) = 6 Then MaskedTextBox4.Mask = "0,00,000" ElseIf Len(str) = 7 Then MaskedTextBox4.Mask = "00,00,000" End If End If End Sub Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MaskedTextBox4.Mask = "0000000" '' End Sub End Class



OUTPUT :-




After Changing value of Cell of Datagridview :- 



Thursday, July 4, 2013

Logic Errors in C# .NET

Logic errors are ones where you don't get the result you were expecting. You won't see any coloured wavy lines, and the programme generally won't "bug out" on you. In other words, you've made an error in your programming logic. As an example, take a look at the following code, which is attempting to add up the numbers one to ten:
A Logic Error in C#
When the code is run, however, it gives an answer of zero. The programme runs OK, and didn't produce any error message or wavy lines. It's just not the correct answer!
The problem is that we've made an error in our logic. The startLoop variable should be 1 and theendLoop variable 11. We've got it the other way round, in the code. So the loop never executes.
Logic errors can be very difficult to track down. To help you find where the problem is, C# has some very useful tools you can use. To demonstrate these tools, here's a new programming problem. We're trying to write a programme that counts how many times the letter "g" appears in the word "debugging".
Start a new C# Windows Application. Add a button and a textbox to your form. Double click the button, and then add the following code:
There's a logic error in this code
The answer should, of course, be 3. Our programme insists, however, that the answer is zero. It's telling us that there aren't and g's in Debugging. So we have made a logic error, but where?
C# .NET has some tools to help you track down errors like this. The first one we'll look at is called the BreakPoint.

Tuesday, July 2, 2013

Logic Errors in C# .NET

Logic errors are ones where you don't get the result you were expecting. You won't see any coloured wavy lines, and the programme generally won't "bug out" on you. In other words, you've made an error in your programming logic. As an example, take a look at the following code, which is attempting to add up the numbers one to ten:
A Logic Error in C#
When the code is run, however, it gives an answer of zero. The programme runs OK, and didn't produce any error message or wavy lines. It's just not the correct answer!
The problem is that we've made an error in our logic. The startLoop variable should be 1 and theendLoop variable 11. We've got it the other way round, in the code. So the loop never executes.
Logic errors can be very difficult to track down. To help you find where the problem is, C# has some very useful tools you can use. To demonstrate these tools, here's a new programming problem. We're trying to write a programme that counts how many times the letter "g" appears in the word "debugging".
Start a new C# Windows Application. Add a button and a textbox to your form. Double click the button, and then add the following code:
There's a logic error in this code
The answer should, of course, be 3. Our programme insists, however, that the answer is zero. It's telling us that there aren't and g's in Debugging. So we have made a logic error, but where?
C# .NET has some tools to help you track down errors like this. The first one we'll look at is called the BreakPoint.

Monday, July 1, 2013

14th Lecture

to see all the tables from the database
command is
select * from sysobjects where type='u'
for making employee id unique and user doesnt froced to enter i t
crete table Employees(Employeeid int primary key identity,Name varchar(50),Department varchar(50))
1 create table
2 cre0te application
3 change name of the form
4 add a new form
5 design the form
6 Move to open coding window of frmEmplloyee With f7
7 declare two datamemebers int localmode and int emlpoyeeid
8 create function named startEmployee in frmEmployee class(build solution)
9 open main from > add a button>write buttons code(run burron application)
10 oppen frmemployee and write save buttoncode(run the appication)
11 open frmmain and add new button > write its code
12 open coding windw of frmemployee and write code in startemployee function
13 Run the application
14 change save button code