if (this.ListBox1.SelectedIndex >= 0 && this.ListBox1.SelectedIndex < ListBox1.Items.Count - 1)
{
string name = ListBox1.SelectedItem.Text;
string ID = ListBox1.SelectedItem.Value;
int index = ListBox1.SelectedIndex;
ListBox1.SelectedItem.Text = ListBox1.Items[index + 1].Text;
ListBox1.SelectedItem.Value = ListBox1.Items[index +1].Value;
ListBox1.Items[index + 1].Text = name;
ListBox1.Items[index + 1].Value = ID;
ListBox1.SelectedIndex++;
}
uj5u.com熱心網友回復:
就是把串列框中選中的那行內容逐行下移到最后uj5u.com熱心網友回復:
把 . 換成 ->
uj5u.com熱心網友回復:
·dataxdata是的啊,也是在網上找到的,不過我只會用C++Builder,Delphi的代碼不能照抄,你能幫我改下嗎?
uj5u.com熱心網友回復:
ccrun將.換成->出錯啊~~~
uj5u.com熱心網友回復:
C++builder將有些Delphi控制元件改過來,格式怪怪的,很麻凡uj5u.com熱心網友回復:
啥也不用說了,你還是把原始的Delphi代碼貼出來吧。
uj5u.com熱心網友回復:
再把string改AnsiStringuj5u.com熱心網友回復:
////////////////////按鈕移動排序
private void moveUpListBox(ListBox ListBox1) //向上移動
{
if (ListBox1.SelectedIndex > 0)
{
int index = ListBox1.SelectedIndex;
string temp = ListBox1.Items[index - 1].ToString();
ListBox1.Items[index - 1] = ListBox1.SelectedItem.ToString(); ;
ListBox1.Items[index] = temp;
ListBox1.SelectedIndex = index - 1;
}
}
private void moveDownListBox(ListBox ListBox1) //向下移動
{
if (ListBox1.SelectedIndex < ListBox1.Items.Count - 1)
{
int index = ListBox1.SelectedIndex;
string temp = ListBox1.Items[index + 1].ToString();
ListBox1.Items[index + 1] = ListBox1.SelectedItem.ToString(); ;
ListBox1.Items[index] = temp;
ListBox1.SelectedIndex = index + 1;
}
}
//up
private void button3_Click(object sender, EventArgs e)
{
moveUpListBox(listBox1);
}
//down
private void button4_Click(object sender, EventArgs e)
{
moveDownListBox(listBox1);
}
uj5u.com熱心網友回復:
沒有人幫 我嗎??uj5u.com熱心網友回復:
你這是C#代碼,不是Delphi代碼。在C++Builder中實作可以這樣://---------------------------------------------------------------------------
// 向上移動
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (ListBox1->ItemIndex < 0) return;
int newIndex = ListBox1->ItemIndex < 1? 0: ListBox1->ItemIndex - 1;
ListBox1->Items->Exchange(ListBox1->ItemIndex, newIndex);
}
//---------------------------------------------------------------------------
// 向下移動
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if (ListBox1->ItemIndex < 0) return;
int newIndex = ListBox1->ItemIndex >= ListBox1->Items->Count - 1?
ListBox1->Items->Count - 1: ListBox1->ItemIndex + 1;
ListBox1->Items->Exchange(ListBox1->ItemIndex, newIndex);
}
uj5u.com熱心網友回復:
非常感謝版主ccrun,我的問題解決了
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/74430.html
標籤:VCL組件使用和開發
上一篇:預編譯宏的問題
