Solved

Events in DataGrid

Posted on 2004-10-07
5
208 Views
Last Modified: 2010-04-23
Hi , i've got a datagrid which shows a table with 3 fields .
how can make it such that when i type in the first 2 fields, the third is generated automatically ?

Thanks in advance
0
Comment
Question by:shenlong_wc
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12256238
You need to trap the event at the underlying table.

Your dataGrid must be bound to a DataTable, this datatable will be having 3 fields which are shown in the DataGrid, so add event handlers to the DataTable

Say you want to trap a change in the column values then

AddHandler DataTable1.ColumnChanged,  New DataColumnChangeEventHandler(AddressOf OnColumnChanged)


Then in the function OnColumnChanged you can get the old and new values etc. and here you can explicitly set the value of the Third column of the row (in the DataTable) to the value you want and it will be reflected in the DataGrid

You can also trap the RowChanged event, the advantage here is you can get to know if it is an Add operation or an Edit operation, because you'd probably want to add new valu to the third column only on the Add operation

AddHandler DataTable1.RowChanged,     New DataRowChangeEventHandler(AddressOf OnRowChanged)

then in the arguments of the OnRowChanged function you'll get an Action property which will tell you whether it is Add or Edit etc.

Look for examples in MSDN for details..

0
 

Author Comment

by:shenlong_wc
ID: 12256419
i'm using a xml source , is there a way for datatable to work with xml ?
0
 

Author Comment

by:shenlong_wc
ID: 12256429
the code i'm using now is

XMLDataSet.ReadXml("settings.xml", XmlReadMode.InferSchema)
DataGrid1.DataSource = XMLDataSet.Tables(1)
0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 50 total points
ID: 12256488
Ok then what you can do is after the line

DataGrid1.DataSource = XMLDataSet.Tables(1)
write

       Dim DT As DataTable
        DT = DataGrid1.DataSource
        AddHandler DT.RowChanged, New DataRowChangeEventHandler(AddressOf OnRowChanged)

then your function will be

Public Sub OnRowChanged(ByVal sender As System.Object, ByVal e As System.Data.DataRowChangeEventArgs)
        'Do what you want here
    End Sub
0
 

Author Comment

by:shenlong_wc
ID: 12256606
worked like a charm . Thanks !
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question