I have a DataGrid which has checkbox columns. The data source is a run-time created data set that I store in a session so I can rebind it during postbacks. I don't have a database or xml file, etc.
I am wondering if it's possible to edit a dataset directly? So when I click on a checkbox it will change the value in the dataset and store it back into session?
If this is not possible how can I use arrays or vectors to temporary store my checkbox statuses? I guess it's not possible to have one DataGrid have more than one datasource...
HELP: Edit a DataSet (not DataGrid)
Page 1 of 12 Replies - 7288 Views - Last Post: 23 May 2006 - 08:51 AM
Replies To: HELP: Edit a DataSet (not DataGrid)
#2
Re: HELP: Edit a DataSet (not DataGrid)
Posted 23 May 2006 - 06:25 AM
Well you can do something like: dataSet1.Tables[0].Rows[4].ItemArray[0] = "NEW VALUE" but since you're clicking a checkbox in the datagrid it should be firing an event that you can handle and then just update the row it is in.
DataRow[] customerRow =
dataSet1.Tables["Customers"].Select("CustomerID = 'ALFKI'");
customerRow[0]["CompanyName"] = "Updated Company Name";
customerRow[0]["City"] = "Seattle";
This post has been edited by sontek: 23 May 2006 - 06:26 AM
#3
Re: HELP: Edit a DataSet (not DataGrid)
Posted 23 May 2006 - 08:51 AM
Yes you can edit the dataset directly, one way is as sontek has already shown.
Although I prefer to use names instead of numbers, it is easier to remember the column names rather than using numbers.
Since you have check boxes, you can use the CheckStateChanged procedure to handle the checkboxes as they are checked/unchecked. They are only boolean values, true = checked and false = not checked.
You could have something like this which will modify the selected row and column in the datagrid:
By using the CurrentRowIndex and the CurrentCell.ColumnNumber, it will modify whichever record in the dataset that you currently working with in your datagrid.
Although I prefer to use names instead of numbers, it is easier to remember the column names rather than using numbers.
Me.DataSet1.Tables("Table name").Rows(0).Item("Column Name") = "New Value"
Since you have check boxes, you can use the CheckStateChanged procedure to handle the checkboxes as they are checked/unchecked. They are only boolean values, true = checked and false = not checked.
You could have something like this which will modify the selected row and column in the datagrid:
Me.DataSet1.Tables("Table name").Rows(Me.DataGrid1.CurrentRowIndex).Item(Me.DataGrid1.CurrentCell.ColumnNumber) = "New Value"
By using the CurrentRowIndex and the CurrentCell.ColumnNumber, it will modify whichever record in the dataset that you currently working with in your datagrid.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|