Gets the collection of columns that are currently selected.
[Visual Basic]
Public ReadOnly Property SelectedCols As SelectedColumnCollection
[C#]
public SelectedColumnCollection SelectedCols {get;}
[Delphi]
public property SelectedCols: SelectedColumnCollection read get_SelectedCols;
Example
The following code is an example of how you can copy a range of cells from a grid to the clipboard and show the range of selected columns and rows in a message box:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' String to be copied to the clipboard.
Dim strTemp As String
Dim row As Long
Dim col As C1.Win.C1TrueDBGrid.C1DataColumn
Dim cols As Integer, rows As Long
If Me.C1TrueDBGrid1.SelectedRows.Count > 0 Then
For Each row In Me.C1TrueDBGrid1.SelectedRows
' Copy everything here.
For Each col In Me.C1TrueDBGrid1.SelectedCols
strTemp = strTemp & col.CellText(row) & vbTab
Next
strTemp = strTemp & vbCrLf
Next
System.Windows.Forms.Clipboard.SetDataObject(strTemp, False)
MsgBox("Range of " & Me.C1TrueDBGrid1.SelectedCols.Count & " x " & C1TrueDBGrid1.SelectedRows.Count & " cells have been copied to the clipboard in TAB delimited format")
Else
MsgBox("Please select a range of cells")
End If
End Sub
· C#
string strTemp = ";
if (this.c1TrueDBGrid1.SelectedRows.Count > 0)
{
foreach (int row in this.c1TrueDBGrid1.SelectedRows)
{
// Copy everything here.
foreach (C1.Win.C1TrueDBGrid.C1DataColumn col in this.c1TrueDBGrid1.SelectedCols)
{
strTemp = strTemp + col.CellText(row) + "\t";
}
strTemp = strTemp + "\n";
}
System.Windows.Forms.Clipboard.SetDataObject(strTemp, false);
MessageBox.Show("Range of " + this.c1TrueDBGrid1.SelectedCols.Count + " x " + this.c1TrueDBGrid1.SelectedRows.Count + " cells have been copied to the clipboard in TAB delimited format");
}
else
{
MessageBox.Show("Please select a range of cells");
}
· Delphi
procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var
StrTemp: string;
i, j, Row: Integer;
Col: C1.Win.C1TrueDBGrid.C1DataColumn;
begin
StrTemp := '';
if (Self.C1TrueDBGrid1.SelectedRows.Count > 0) then
begin
for i := 0 to C1TrueDBGrid1.SelectedRows.Count-1 do
begin
Row := C1TrueDBGrid1.SelectedRows[i];
// Copy everything here.
for j := 0 to C1TrueDBGrid1.SelectedCols.Count-1 do
begin
Col := C1TrueDBGrid1.SelectedCols[j];
StrTemp := StrTemp + col.CellText(Row) + #9;
strTemp := strTemp + #13;
end;
end;
System.Windows.Forms.Clipboard.SetDataObject(StrTemp, False);
MessageBox.Show('Range of ' + C1TrueDBGrid1.SelectedCols.Count.ToString + ' x ' + Self.C1TrueDBGrid1.SelectedRows.Count.ToString + ' cells have been copied to the clipboard in TAB delimited format');
end;
else
MessageBox.Show('Please select a range of cells');
end;
See Tutorial 19 - Range Selection to see this code used within an application.
See Also
C1TrueDBGrid Class | C1TrueDBGrid Members | C1.Win.C1TrueDBGrid Namespace
Send comments about this topic to ComponentOne. Copyright © ComponentOne LLC. All rights reserved. |