Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DataGrid

DataGrid

Scheduled Pinned Locked Moved C#
csswinformstutorialquestionannouncement
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bahadir Cambel
    wrote on last edited by
    #1

    How could I change the data source of a dataGrid in run time (Windows Forms)? datagrid.Update() What I am trying to do is, to change the data source of the data grid with respect to CustomerID.. If customerID is changed, than the dataView will retrieve the data from DataSet table and then update the datagrid ,without changing data source , update data source with DataView But I couldnt find the method, please guide me to achieve. Is it possible ? Thanks , Bahadir Cambel

    K 1 Reply Last reply
    0
    • B Bahadir Cambel

      How could I change the data source of a dataGrid in run time (Windows Forms)? datagrid.Update() What I am trying to do is, to change the data source of the data grid with respect to CustomerID.. If customerID is changed, than the dataView will retrieve the data from DataSet table and then update the datagrid ,without changing data source , update data source with DataView But I couldnt find the method, please guide me to achieve. Is it possible ? Thanks , Bahadir Cambel

      K Offline
      K Offline
      Kodanda Pani
      wrote on last edited by
      #2

      Hi, Why to change the datasource? Instead that we can associate the Dataview to the datagrid. Filter the DataSet into Dataview using RowFilter and RowStateFilter properties of Dataview. Dataview.RowFilter = "customerID=xxxx"; Thanks SGS

      B 1 Reply Last reply
      0
      • K Kodanda Pani

        Hi, Why to change the datasource? Instead that we can associate the Dataview to the datagrid. Filter the DataSet into Dataview using RowFilter and RowStateFilter properties of Dataview. Dataview.RowFilter = "customerID=xxxx"; Thanks SGS

        B Offline
        B Offline
        Bahadir Cambel
        wrote on last edited by
        #3

        thanks for the reply , but my problem is to update the datagrid. I can not update the dataGrid when I change the dataView. To be more specific I have a curreny manager which is holding the information about the customers named cm I have 2 dataTables dt_Orders and dt_Customers for orders and customers I inserted the update operation into ShowCurrentRecord which is called when CurrenyManager_PositionChanged event..

        		private void cm_PositionChanged(object sender, EventArgs e)
        		{
        			ShowCurrentRecord();
        		}
        	private void ShowCurrentRecord()
        		{
        string CustomerID=ds_Customers.Tables["dt_Customers"].Rows[cm.Position]["CustomerID"].ToString();
        for(int i =0 ;i <RowCount ;i++)
        { //If the selected Customer has an Order(s) in dt_Orders, update the dataGrid
        if ( ds_Customers.Tables["dt_Orders"].Rows[i]["CustomerID"].ToString()==CustomerID ) 
        {myDataView.RowFilter="CustomerID="+CustomerID;
        

        It turned out to be , I can not set anything into RowFilter.. even if I tried dv.RowFilter="CustomerID"+CustomerID; dv.AllowEdit(); dv.BeginInit(); When I use Watch the find the value , although CustomerID has its value , watch always shows RowFilter as null string.. Does dataView can be edited in run-time ?

        B 1 Reply Last reply
        0
        • B Bahadir Cambel

          thanks for the reply , but my problem is to update the datagrid. I can not update the dataGrid when I change the dataView. To be more specific I have a curreny manager which is holding the information about the customers named cm I have 2 dataTables dt_Orders and dt_Customers for orders and customers I inserted the update operation into ShowCurrentRecord which is called when CurrenyManager_PositionChanged event..

          		private void cm_PositionChanged(object sender, EventArgs e)
          		{
          			ShowCurrentRecord();
          		}
          	private void ShowCurrentRecord()
          		{
          string CustomerID=ds_Customers.Tables["dt_Customers"].Rows[cm.Position]["CustomerID"].ToString();
          for(int i =0 ;i <RowCount ;i++)
          { //If the selected Customer has an Order(s) in dt_Orders, update the dataGrid
          if ( ds_Customers.Tables["dt_Orders"].Rows[i]["CustomerID"].ToString()==CustomerID ) 
          {myDataView.RowFilter="CustomerID="+CustomerID;
          

          It turned out to be , I can not set anything into RowFilter.. even if I tried dv.RowFilter="CustomerID"+CustomerID; dv.AllowEdit(); dv.BeginInit(); When I use Watch the find the value , although CustomerID has its value , watch always shows RowFilter as null string.. Does dataView can be edited in run-time ?

          B Offline
          B Offline
          Bahadir Cambel
          wrote on last edited by
          #4

          Hahahah , the whole problem was myDataView.RowFilter = "CustomerID= '"+CustomerID+"'"; : )

          K 1 Reply Last reply
          0
          • B Bahadir Cambel

            Hahahah , the whole problem was myDataView.RowFilter = "CustomerID= '"+CustomerID+"'"; : )

            K Offline
            K Offline
            Kodanda Pani
            wrote on last edited by
            #5

            Ok. Guess your problem is solved now :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups