求助!!~~~~急 在ListBox中实现多重选项,第一个选中就在其内容后面标识1,第二个选中就的标识2,以此类推X 1Y 2Z 3如果取消选项,将重排数字,就是将其后面的序号提前。X 1Z 2 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在ListBox中实现多重选项,第一个选中就在其内容后面标识1,第二个选中就的标识2,以此类推比如:ListBox有3个选项,X,Y,Z,首先选择X,所以在X后面加1.....X 1Y 2Z 3如果取消选项,将重排数字,就是将其后面的序号提前。现在有3个选项都选中,现在再选择Y,,将会是下面的结果X 1YZ 2 private Dictionary<string, int> m_AllItems = new Dictionary<string, int>(); private int m_Index = 1;string strSelText = listBox1.SelectedItem.ToString(); if (!m_AllItems.ContainsKey(strSelText)) { m_AllItems.Add(strSelText, m_Index); m_Index++; } else { m_AllItems.Remove(strSelText); foreach (string key in m_AllItems.Keys) { m_AllItems[key]--; } m_Index--; } this.textBox1.Text = ""; foreach (string strKey in m_AllItems.Keys) { this.textBox1.Text += strKey + " " + m_AllItems[strKey].ToString() + " "; } Dictionary,命名空间是什么?? 是不是写在listBox1_SelectedIndexChanged事件中 private void listBox1_DrawItem(object sender, DrawItemEventArgs e){ e.DrawBackground(); string s = ""; if (((ListBox)sender).GetSelected(e.Index)) { int j = 0; for (int i = 0; i <= e.Index; i++) if (((ListBox)sender).GetSelected(i)) j++; s = " " + j.ToString(); } e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString() + s, e.Font, new SolidBrush(e.ForeColor), e.Bounds, StringFormat.GenericDefault); e.DrawFocusRectangle();}private void listBox1_SelectedValueChanged(object sender, EventArgs e){ ((ListBox)sender).Invalidate();}private void Form1_Load(object sender, EventArgs e){ listBox1.DrawMode = DrawMode.OwnerDrawFixed;} private System.Collections.ArrayList SelectedItems; public Form1() { InitializeComponent(); listBox1.DrawMode = DrawMode.OwnerDrawFixed; SelectedItems = new System.Collections.ArrayList(); } private void listBox1_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); string s = ""; int j = SelectedItems.IndexOf(this.listBox1.Items[e.Index]); if( j>-1) s = " " + (j+1).ToString(); e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString() + s, e.Font, new SolidBrush(e.ForeColor), e.Bounds, StringFormat.GenericDefault); e.DrawFocusRectangle(); } private void listBox1_SelectedValueChanged(object sender, EventArgs e) { // 删除掉被取消选中的项 for (int i = 0; i < SelectedItems.Count; i++) { if (!this.listBox1.SelectedItems.Contains(SelectedItems[i])) { this.SelectedItems.RemoveAt(i); i--; } } // 加上被选中的项 for (int i = 0; i < this.listBox1.SelectedItems.Count; i++) { if (!SelectedItems.Contains(this.listBox1.SelectedItems[i])) { SelectedItems.Add(this.listBox1.SelectedItems[i]); } } ((ListBox)sender).Invalidate(); }---------------------调试通过了,zswang(伴水清清)(专家门诊清洁工)的Draw解决的大问题。 关于webservice 提交dataset里的xml 线程 join 问题 谢谢 c# 的一些小问题 很有点麻烦,不知如何解决,向高手请教、、、、 求救!为什把密码加密后就登录不了了? IIS ISAPI 高手请进 |ZYCIIS| 求一个WPF的Word控件和一些WPF操作Word的文章 谢谢 c#播放flash,背景透明 网页上的.NET源码 在程序中弹出一个对话框,怎么获取用户的选择?代码附内 请问 vc++ 6.0的项目怎么在vs2005下面编译 遇见一个问题 请问怎么解决 请问在GroupBox里如何动态增加文本框?
X 1
Y 2
Z 3如果取消选项,将重排数字,就是将其后面的序号提前。现在有3个选项都选中,现在再选择Y,,将会是下面的结果X 1
Y
Z 2
if (!m_AllItems.ContainsKey(strSelText))
{
m_AllItems.Add(strSelText, m_Index);
m_Index++;
}
else
{
m_AllItems.Remove(strSelText);
foreach (string key in m_AllItems.Keys)
{
m_AllItems[key]--;
}
m_Index--;
} this.textBox1.Text = "";
foreach (string strKey in m_AllItems.Keys)
{
this.textBox1.Text += strKey + " " + m_AllItems[strKey].ToString() + " ";
}
{
e.DrawBackground();
string s = "";
if (((ListBox)sender).GetSelected(e.Index))
{
int j = 0;
for (int i = 0; i <= e.Index; i++)
if (((ListBox)sender).GetSelected(i)) j++;
s = " " + j.ToString();
}
e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString() + s,
e.Font, new SolidBrush(e.ForeColor), e.Bounds,
StringFormat.GenericDefault);
e.DrawFocusRectangle();
}private void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
((ListBox)sender).Invalidate();
}private void Form1_Load(object sender, EventArgs e)
{
listBox1.DrawMode = DrawMode.OwnerDrawFixed;
}
public Form1()
{
InitializeComponent();
listBox1.DrawMode = DrawMode.OwnerDrawFixed;
SelectedItems = new System.Collections.ArrayList();
} private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground(); string s = "";
int j = SelectedItems.IndexOf(this.listBox1.Items[e.Index]);
if( j>-1)
s = " " + (j+1).ToString(); e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString() + s,
e.Font, new SolidBrush(e.ForeColor), e.Bounds,
StringFormat.GenericDefault);
e.DrawFocusRectangle();
} private void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
// 删除掉被取消选中的项
for (int i = 0; i < SelectedItems.Count; i++)
{
if (!this.listBox1.SelectedItems.Contains(SelectedItems[i]))
{
this.SelectedItems.RemoveAt(i);
i--;
}
}
// 加上被选中的项
for (int i = 0; i < this.listBox1.SelectedItems.Count; i++)
{
if (!SelectedItems.Contains(this.listBox1.SelectedItems[i]))
{
SelectedItems.Add(this.listBox1.SelectedItems[i]);
}
} ((ListBox)sender).Invalidate();
}---------------------
调试通过了,zswang(伴水清清)(专家门诊清洁工)的Draw解决的大问题。