MultiRow Windows Forms > Developer's Guide > Using MultiRow > Managing Data > Get and Set Data |
You can get cell values from the GcMultiRow control using various methods. The values can be handled in MultiRow as shown below.
Values other than the cell values (Cell.Value property) are read-only.
Cell values are set with the GcMultiRow.SetValue method.
The following code sets the value in the second cell of the first row.
GcMultiRow1.SetValue(0, 1, "ABC") |
gcMultiRow1.SetValue(0, 1, "ABC"); |
Use the GcMultiRow.GetValue method to get the cell values.
The following code gets the value of the second cell of the first row and shows it in the console.
Dim cellValue As Object = GcMultiRow1.GetValue(0, 1) Console.WriteLine(cellValue) |
object cellValue = gcMultiRow1.GetValue(0, 1); Console.WriteLine(cellValue); |
You can also get and set cell values through the row and cell instances. Use the GcMultiRow.GetValue and GcMultiRow.SetValue methods to work with the values.
This example gets and sets values in cells.
GcMultiRow1.Rows(0).Cells(1).Value = "DEF" GcMultiRow1(0, 2).Value = "GHI" Console.WriteLine(GcMultiRow1(0, 2).Value) |
gcMultiRow1.Rows[0].Cells[1].Value = "DEF"; gcMultiRow1[0, 2].Value = "GHI"; Console.WriteLine(gcMultiRow1[0, 2].Value); |
The cell values are always of the System.Object type. You can confirm this by using the Cell.ValueType property to check the data type of the cell value.
Use the GcMultiRow.GetFormattedValue method to get the formatted value related to the cell.
The following code gets the value of the second cell of the first row and outputs it to the console.
Dim formattedValue As Object = GcMultiRow1.GetFormattedValue(0, 1) Console.WriteLine(formattedValue) |
object formattedValue = gcMultiRow1.GetFormattedValue(0, 1); Console.WriteLine(formattedValue); |
You can also get and set the formatted cell values through the row and cell instances. Use the GcMultiRow.GetFormattedValue method to work with formatted cell values.
This example gets the formatted cell value.
Dim formattedValue As Object = GcMultiRow1(0, 1).FormattedValue Console.WriteLine(formattedValue) |
object formattedValue = gcMultiRow1[0, 1].FormattedValue; Console.WriteLine(formattedValue); |
The data type of the formatted value can be returned with the Cell.FormattedValueType property. Unlike the Cell.ValueType property, the Cell.FormattedValueType property returns the data type aligned with the actual display.
The result of the following code is String for String type, and Date (System.DateTime in C#) for Date type.
Console.WriteLine(GcMultiRow1(0, 1).FormattedValueType) |
Console.WriteLine(gcMultiRow1[0, 1].FormattedValueType); |
If the cell is still in edit mode or the values have not been saved, the Cell.FormattedValue property may not return the current value (since the values have still not been confirmed). In order to get the formatted cell value, regardless of editing state or saving, use the GcMultiRow.GetEditedFormattedValue method or the Cell.EditedFormattedValue property. The cell value format can be customized using the CellFormatting event.
Use the GcMultiRow.GetDisplayText method to get the values displayed in the cells.
This example gets the value in the cell.
Dim displayValue As String = GcMultiRow1.GetDisplayText(0, 1) Console.WriteLine(displayValue) |
string displayValue = gcMultiRow1.GetDisplayText(0, 1); Console.WriteLine(displayValue); |
You can also get and set the displayed values through the row and cell instances. Use the GcMultiRow.GetDisplayText method to work with the displayed values.
This example uses the GetDisplayText method.
Console.WriteLine(GcMultiRow1(0, 2).DisplayText) |
Console.WriteLine(gcMultiRow1[0, 2].DisplayText); |
The value of the cell is always String type.
|
The values in edit mode can be returned using System.Windows.Forms.Control.Text.
The following code gets the values in edit mode.
Dim editingControlValue As String = GcMultiRow1.EditingControl.Text Console.WriteLine(editingControlValue) |
string editingControlValue = gcMultiRow1.EditingControl.Text; Console.WriteLine(editingControlValue); |
In order to access the default cell values for a newly added row, access the cell values of the template. Use the NewRowNeeded event to set the default value in the cells when a new row is added.