Solved

Events in DataGrid

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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