Solved

Events in DataGrid

Posted on 2004-10-07
5
188 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now