网站建设资讯

NEWS

网站建设资讯

vb.net文字排序 vb数字排序代码

VB.NET中数据的排序问题

建议用 DataGridView(你用的是它吧?)内建的排序方法来排序。介绍和示例代码可以参考MSDN:

在茂南等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、成都网站制作 网站设计制作按需策划,公司网站建设,企业网站建设,成都品牌网站建设,全网营销推广,外贸营销网站建设,茂南网站建设费用合理。

VB.net 排序

你这个是冒泡排序么?从大到小么?

For j = 0 To lstNetworkRisk.Items.Count - 1 应该改成

For j = i To lstNetworkRisk.Items.Count - 1

另外尽量不要用GOTO语句。而且完全也可以不用这个GOTO。

还有不知道你用的什么版本的.net 如果是3.5的完全可以直接用linq。

vb.net读取txt文件,按照要求排序其中数据后显示在listbox控件中。

说一个可行的方案。你可以用3个ListBox,当然其中两个个可以设为不可见。先读两行加入到ListBox1中,接着读两行写入ListBox2中,如此循环到文件结束。按照你给的例子,现在Listbox

1中的items是A,B,E,F;而ListBox2中的Items是C,D,G,H。接下来的你应该就明白了吧,把ListBox2中的Items和对应的ListBox1中Item加到ListBox3中。下面简单写下代码,主要是处理问题的思路,代码很简单。

Private Sub DoList(ByVal filePath As String)

Dim str As String

Dim num

Dim listCount

Dim sr As StreamReader

sr = New System.IO.StreamReader(filePath, System.Text.Encoding.Default)

str = sr.ReadLine()

Do While (sr.Peek = 0)

For num=0 To 2

str = sr.ReadLine()

ListBox1.items.Add(str)

Next

num=0

For num=0 To 2

str = sr.ReadLine()

ListBox2.items.Add(str)

Next

Loop

sr.Close()

For listCount=o To ListBox2.Items.Count-1

ListBox3..Items.Add(ListBox1.Items(listCount).ToString+

vb.net datagridview 几行一起排序

黑体字下面是要这样吗? vb的代码 我不太懂,只会c#的,  但是给你个思路, 就是纵向合并单元格嘛。 

我贴一段c#的代码,。, 您理解下, 应该不困难。。。

代码 把AllowUserToAddRows设置为false

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)

{

//纵向合并

if (this.dataGridView1.Columns["Name"].Index == e.ColumnIndex e.RowIndex = 0)

{

using (

Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),

backColorBrush = new SolidBrush(e.CellStyle.BackColor))

{

using (Pen gridLinePen = new Pen(gridBrush))

{

// 擦除原单元格背景

e.Graphics.FillRectangle(backColorBrush, e.CellBounds);

/**/

////绘制线条,这些线条是单元格相互间隔的区分线条,

////因为我们只对列name做处理,所以datagridview自己会处理左侧和上边缘的线条

if (e.RowIndex != this.dataGridView1.RowCount - 1)

{

try

{

if (e.Value.ToString() != this.dataGridView1.Rows[e.RowIndex +

1].Cells[e.ColumnIndex].Value.ToString())

{

e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1,

e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);//下边缘的线

//绘制值

if (e.Value != null)

{

e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,

Brushes.Crimson, e.CellBounds.X + 2,

e.CellBounds.Y + 2, StringFormat.GenericDefault);

}

}

}

catch (Exception ex)

{

}

}

else

{

e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1,

e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);//下边缘的线

//绘制值

if (e.Value != null)

{

e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,

Brushes.Crimson, e.CellBounds.X + 2,

e.CellBounds.Y + 2, StringFormat.GenericDefault);

}

}

//右侧的线

e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,

e.CellBounds.Top, e.CellBounds.Right - 1,

e.CellBounds.Bottom - 1);

e.Handled = true;

}

}

}

}

下面是我用的datatable   这个dataset是网上copy的

DataSet dataset = new DataSet();//库

//表

DataTable myfriends = new DataTable("myfriends");

//列

DataColumn dcName = new DataColumn();

dcName.ColumnName = "Name";

dcName.DataType = typeof(string);

dcName.MaxLength = 8;

DataColumn dcPhone = new DataColumn();

dcPhone.ColumnName = "telephone";

dcPhone.DataType = typeof(string);

dcPhone.MaxLength = 11;

//添加列

myfriends.Columns.Add(dcName);

myfriends.Columns.Add(dcPhone);

//添加1行

DataRow row = myfriends.NewRow();//得到空行

row["Name"] = "小明";

row["telephone"] = "13888888888";

DataRow row1 = myfriends.NewRow();//得到空行

row1["Name"] = "小明";

row1["telephone"] = "15859859888";

DataRow row2 = myfriends.NewRow();//得到空行

row2["Name"] = "猪猪";

row2["telephone"] = "15999999999";

myfriends.Rows.Add(row);

myfriends.Rows.Add(row1);

myfriends.Rows.Add(row2);

//添加表到dataset

dataset.Tables.Add(myfriends);

dataGridView1.DataSource = myfriends;


分享名称:vb.net文字排序 vb数字排序代码
标题URL:http://cdweb.net/article/doecgsi.html