Solved

Events in DataGrid

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

19 Experts available now in Live!

Get 1:1 Help Now