GrapeCity MultiRow Windows Forms Documentation
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.

  1. Cell.Value - Save the value as an Object.
  2. Cell.FormattedValue - Change the cell value as a formatted value based on the data type and style.
  3. Cell.DisplayText - Change the formatted value to a display value depending on the specific settings of each cell type.

Values other than the cell values (Cell.Value property) are read-only.

Get and Set Cell Values

Cell values are set with the GcMultiRow.SetValue method.

Using Code

The following code sets the value in the second cell of the first row.

[VB]

GcMultiRow1.SetValue(0, 1, "ABC")

[CS]

gcMultiRow1.SetValue(0, 1, "ABC");

Use the GcMultiRow.GetValue method to get the cell values.

Using Code

The following code gets the value of the second cell of the first row and shows it in the console.

[VB]

Dim cellValue As Object = GcMultiRow1.GetValue(0, 1)
Console.WriteLine(cellValue)

[CS]

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.

Using Code

This example gets and sets values in cells.

[VB]

GcMultiRow1.Rows(0).Cells(1).Value = "DEF"
GcMultiRow1(0, 2).Value = "GHI"
Console.WriteLine(GcMultiRow1(0, 2).Value)

[CS]

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.

Get the Formatted Cell Value

Use the GcMultiRow.GetFormattedValue method to get the formatted value related to the cell.

Using Code

The following code gets the value of the second cell of the first row and outputs it to the console.

[VB]

Dim formattedValue As Object = GcMultiRow1.GetFormattedValue(0, 1)
Console.WriteLine(formattedValue)

[CS]

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.

Using Code

This example gets the formatted cell value.

[VB]

Dim formattedValue As Object = GcMultiRow1(0, 1).FormattedValue
Console.WriteLine(formattedValue)

[CS]

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.

Using Code

The result of the following code is String for String type, and Date (System.DateTime in C#) for Date type.

[VB]

Console.WriteLine(GcMultiRow1(0, 1).FormattedValueType)

[CS]

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.

Get the Displayed Cell Values

Use the GcMultiRow.GetDisplayText method to get the values displayed in the cells.

Using Code

This example gets the value in the cell.

[VB]

Dim displayValue As String = GcMultiRow1.GetDisplayText(0, 1)
Console.WriteLine(displayValue)

[CS]

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.

Using Code

This example uses the GetDisplayText method.

[VB]

Console.WriteLine(GcMultiRow1(0, 2).DisplayText)

[CS]

Console.WriteLine(gcMultiRow1[0, 2].DisplayText);

The value of the cell is always String type.

  • The checkbox type cell always returns the CheckBoxCell.Text property. It does not return the cell value.
  • The Radio group type cells return the string of the selected item. They return String.Empty when no item is selected.
  • Image and track bar type cells always return String.Empty.

Get the Values in Edit mode

The values in edit mode can be returned using System.Windows.Forms.Control.Text.

Using Code

The following code gets the values in edit mode.

[VB]

Dim editingControlValue As String = GcMultiRow1.EditingControl.Text
Console.WriteLine(editingControlValue)

[CS]

string editingControlValue = gcMultiRow1.EditingControl.Text;
Console.WriteLine(editingControlValue);

Get the Default Cell Values

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.

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options