Miro wrote:
(1)
How did you get this example to work:
<example>
Me.dgvmyData.Sort(Me.CustomerNameDataGridViewTextBoxColumn, _
System.ComponentModel.ListSortDirection.Ascending)
</example>
By putting 'just the txtColumnName' in the first variable of the sort -
you
will get a runtime error that the column does not exist in the
datagridview.
</snip>
(2)
By going back to my original example, and using the
Me.dgvmyData.Columns.Item("txtColName") example, this only allows 2
overloads. 1 is the column index, and 2 is the Name as string.
I am looking for some overload to put the actual column name in there.
</snip>
Hi, Miro!
1) Of course, you must use the actual control name, I don't know how
the editor named the controls for the columns you are using. To see
the actual control name, right-click the grid, select "Edit
columns...", select the column in the left panel (under "selected
columns") and verify its name in the right panel (under "Bound Column
Properties"). The control name will be in the (Name) field.
2) Maybe I'm not being clear enough. I'm talking about the actual
column control as parameter for the **DataGridView.Sort** method, not
the parameter for the **DataGriView.Column.Item** property.
These column controls were created automatically for you and are
accessible at form level, just type Me, dot, and presto!, the control
list will appear, pick the column control name from there! =))).
(That's why I rename then, it's way easier to pick then up when you
actually know the control's name! =))
You are correct in not wanting to use the "string name" or the
column's index. If you ever need a column's name or index, you can get
then from the control itself (from the properties "Name", "Index" or
"DisplayIndex").
Hope this helps.
Branco.
==============================
Hi Branco,
I must still be missing something:
My datagrid name is dgvRounds
My column ( or one of them ) is named 'txtRounds' - i have already renamed
it.
I have my data filled in the datagrid.
What I am understanding is that I can sort my datagrid like this ( by your
code )
Me.dgvRounds.Sort(Me.txtRound,
System.ComponentModel.ListSortDirection.Ascending)
The error I get - during runtime is:
Column provided does not belong to this DataGridVew control
The way I am adding the column is like this:
On the form load:
Dim index As Integer
Dim dgvMaskedEdit As DataGridViewMaskedEditColumn 'custom class
that is a masked edit column
'find old column that is just a text box and remove it and add the
masked edit text box in its place.
index = dgvRounds.Columns.IndexOf(dgvRounds.Columns("txtRound"))
dgvRounds.Columns.Remove("txtRound")
' create a new custom column
dgvMaskedEdit = New DataGridViewMaskedEditColumn
dgvMaskedEdit.Mask = "###"
dgvMaskedEdit.PromptChar = " "c
dgvMaskedEdit.ValidatingType = GetType(Integer)
dgvMaskedEdit.Name = "txtRound"
dgvMaskedEdit.DataPropertyName = "PlayRound"
dgvMaskedEdit.HeaderText = "Round"
' some more tweaking
dgvMaskedEdit.SortMode = DataGridViewColumnSortMode.Programmatic
' insert the new column at the same location
dgvRounds.Columns.Insert(index, dgvMaskedEdit)
------
so i can access Me.txtRound as a control, but I cannot figure out how to
sort it by that column using the datagridview, unless i use "txtRound"
You mentioned the "method"...im looking for help here:
http://msdn.microsoft.com/en-us/library/ms171608.aspx
and cant seem to find what you are refering to.
I have found this link:
http://msdn.microsoft.com/en-us/library/0868ft3z.aspx
In the example given, it gets the index thru searching which column is
selected.
I know my index by index =
dgvRounds.Columns.IndexOf(dgvRounds.Columns("txtRound"))
Thank you for your patients.
Miro