Solved

Events in DataGrid

Posted on 2004-10-07
5
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 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