成都网站建设设计

将想法与焦点和您一起共享

vb点虐 自定义排序列 vbasort函数自定义排序序列

c#或者vb点虐 如何实现类似Excel的自定义排序

原理应该是这样的,先用主要关键字排序,主要关键字相同的继续按次要关键字排序

成都网络公司-成都网站建设公司成都创新互联10多年经验成就非凡,专业从事网站设计制作、网站建设,成都网页设计,成都网页制作,软文营销一元广告等。10多年来已成功提供全面的成都网站建设方案,打造行业特色的成都网站建设案例,建站热线:18982081108,我们期待您的来电!

VB.NET中DATAGRIDVIEW做排名(要序号)求助!!!

第一种方式:手动设置,设置列允许重新排列,这样在单击datagridview的列名时,就会自动排序

第二种方式:自动排序,想要按那列排序,就设置那列的SortMode的属性为:Programmatic

VB.NET 如何实现DataGridView自定义排序?

设置了Column.SortMode = DataGridViewColumnSortMode.Automatic 后按了列标题后只有默认的排序。

我想实现自己的排序规则。

MSDN上招到了下面这段

Private Sub DataGridView1_SortCompare( _

ByVal sender As Object, ByVal e As DataGridViewSortCompareEventArgs) _

Handles DataGridView1.SortCompare

' Try to sort based on the contents of the cell in the current column.

e.SortResult = System.String.Compare(e.CellValue1.ToString(), _

e.CellValue2.ToString())

' If the cells are equal, sort based on the ID column.

If (e.SortResult = 0) AndAlso Not (e.Column.Name = "ID") Then

e.SortResult = System.String.Compare( _

DataGridView1.Rows(e.RowIndex1).Cells("ID").Value.ToString(), _

DataGridView1.Rows(e.RowIndex2).Cells("ID").Value.ToString())

End If

e.Handled = True

End Sub

但是我是用DataSource绑定数据不能触发SortCompare。

只有当未设置 DataSource 属性,并且 VirtualMode 属性值为 false 时,此事件才会发生。

IComparer 接口DataGridView1.Sort(New RowComparer(SortOrder.Descending)) 也不行。

vB点虐 语言编写N个数字数组排序可自定义数组长度的

Dim d() As Integer

Dim n As Integer

Dim i As Integer

Dim j As Integer

Dim T As Integer

n = Val(InputBox("请输入n,确定数组的元素个数"))

ReDim d(n)

'用随机函数生成正整数数组

Randomize

For i = 1 To n

d(i) = Int(Rnd * 100 + 1)

Next i

'输出

Print

For i = 1 To n

Print d(i),

Next i

'从小到大排序

For i = 1 To n - 1

For j = i + 1 To n

If d(i) d(j) Then

T = d(i)

d(i) = d(j)

d(j) = T

End If

Next j

Next i

'输出

Print

For i = 1 To n

Print d(i),

Next i


分享标题:vb点虐 自定义排序列 vbasort函数自定义排序序列
标题URL:http://chengdu.cdxwcx.cn/article/ddjhdio.html