Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / how to get dataset from a grid which has already bound to a dataset

how to get dataset from a grid which has already bound to a dataset

New Discussion
rajathan
rajathan asked on Aug 26, 2008 1:09 PM

 I have a datagrid wich is already bound to a dataset, I need toget this dataset,make changes on some data, then rebind the datagrid with the modified dataset. Like this:

datagrid1.datasource=ds1;

……….

//how to get the dataset from the datagrid???

ds2=datagrid1.datasource;

make changes on ds2;

datagrid1.datasource=ds2;

Sign In to post a reply

Replies

  • 0
    Andrej Kuklin
    Andrej Kuklin answered on Aug 26, 2008 11:49 AM

    1. [quote user="rajathan"]//how to get the dataset from the datagrid??? [/quote] 

      DataSet ds2 = (DataSet)datagrid1.datasource;

     

    2. [quote user="rajathan"]rebind the datagrid with the modified dataset.[/quote] 

    In general you don't need to rebind the dataset (or need something else to update the grid). The grid should react to changes in the data source. This is the main concept of data binding. There are though some … small features in dataset events which should be taken into account. If your grid does not update itself after your operations with the dataset – post a message here. There are workarounds to make datagrid update itself (explicit calls).

    • 0
      rajathan
      rajathan answered on Aug 26, 2008 12:08 PM

       Hi,Andrej

      thanks for the answer, but I got exception at    DataSet ds2 = (DataSet)datagrid1.datasource;

      It said:"Unable to cast object of type 'System.Windows.Forms.BindingSource' to 'System.Data.DataSet'"

       

      I have 2 ultragrid, A and B. what I want is: when I double click on one row in A, this row will be removed from A, and also that row will be removed from the dataset which is bound to A; mean while, I want to add this row to B, and that row will also be added to the dataset which is bound to B.

      Do you know what I mean?

       

      • 0
        Andrej Kuklin
        Andrej Kuklin answered on Aug 26, 2008 12:21 PM

        1. [quote user="rajathan"]

        thanks for the answer, but I got exception at    DataSet ds2 = (DataSet)datagrid1.datasource;

        It said:"Unable to cast object of type 'System.Windows.Forms.BindingSource' to 'System.Data.DataSet'"

        [/quote]

        Please, provide the code for your initial databinding (probably it's not just  datagrid1.datasource=ds1;). Also, to be sure we're not too out-of-date: what version of NetAdvantage you use? (and is datagrid1 actually and UltraWinGrid control?)

         2.  [quote user="rajathan"]I have 2 ultragrid, A and B. what I want is: when I double click on one row in A, this row will be removed from A, and also that row will be removed from the dataset which is bound to A; mean while, I want to add this row to B, and that row will also be added to the dataset which is bound to B.[/quote]

        Yes, this should (in general) work without any explicit refresh/update calls.

      • 0
        rajathan
        rajathan answered on Aug 26, 2008 12:32 PM

         Hi Andre

        Thranks again for the reply. the code is:

        DataSet ds = get data from DB;    // use  _db.LoadDataSet(cmd, theDataSet, tableName) to load dataset;

        BindingSource gridSource = new BindingSource(ds, .TableName);

        grid.DataSource = gridSource ;

        The version version of NetAdvantage is 2007 Vol. 2;

         

         

         

      • 0
        Andrej Kuklin
        Andrej Kuklin answered on Aug 26, 2008 12:47 PM

        Try

        DataSet ds = (DataSet)((BindingSource)grid.DataSource).DataSource

      • 0
        rajathan
        rajathan answered on Aug 26, 2008 1:01 PM

        Dear Andrej

        Thanks a lot for your help, it works now!

        Thank you very much!!!

      • 0
        Andrej Kuklin
        Andrej Kuklin answered on Aug 26, 2008 1:09 PM

        You're welcome 

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
rajathan
Favorites
0
Replies
7
Created On
Aug 26, 2008
Last Post
18 years, 1 month ago

Suggested Discussions

Tags

Created by

Created on

Aug 26, 2008 1:09 PM

Last activity on

Aug 26, 2008 1:09 PM