Datagrid in winform
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Datagrid in winform

  1. #1
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    242

    Datagrid in winform

    Hi All,

    I'm working on winforms for the first time. I want a datagrid to display the data and be able to edit and update the same. It displays the data. But, I have not been able to make the Datagrid editable. Can anybody please gimme some quick tips for this or best gimme a link for how to edit the data in a winform datagrid?
    Hope this helps. If it does, then rate it.
    ----
    Rohit

  2. #2
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: Datagrid in winform

    That depends on how you load the data into the DataGrid.
    Whic class do you use as DataSource? Is it from a database?

  3. #3
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    242

    Re: Datagrid in winform

    The data is surely from a database and I load my database using a custom collection class I have created. Also, I need to know what do I need to make my grid eidtable (find the selected row or inline editing etc. as in ASP.Net).
    Hope this helps. If it does, then rate it.
    ----
    Rohit

  4. #4
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: Datagrid in winform

    Inserting/Updating/Deleting Records using DataGrid
    Code:
    dataset ds = new dataset(); 
    OleDb.OleDbConnection con = new OleDb.OleDbConnection(yourconnectionstring); 
    OleDb.OleDbDataAdapter da = new OleDb.OleDbDataAdapter("select * from yourtable", con); 
    da.fill(ds); 
    datagrid1.datasource = ds.tables(0);
    Now you can add/delete/update the records in your datagrid. To save the changes you made back to the database
    do something like (like behind a save button)
    Code:
    OleDb.OleDbCommandBuilder cm = new OleDb.OleDbCommandBuilder(da); 
    da.update(ds);

  5. #5
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    242

    Re: Datagrid in winform

    Thats what I want Anis.... How do I add, modify and delete records from the dataagrid (Winform)
    Hope this helps. If it does, then rate it.
    ----
    Rohit

  6. #6
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: Datagrid in winform

    u bound the datagrid with the datatable
    then make modifications in the datagrid.
    when u are ready to set the change to the database as until now u have modified the datatable.
    press update(button) it creates the commandBuilder for the dataAdapter and then updates the database.

  7. #7
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    242

    Re: Datagrid in winform

    can u post some code as an example
    Hope this helps. If it does, then rate it.
    ----
    Rohit

  8. #8
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: Datagrid in winform

    sample
    Attached Files Attached Files

  9. #9
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    242

    Re: Datagrid in winform

    Thanks
    Hope this helps. If it does, then rate it.
    ----
    Rohit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center