| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 472 人关注过本帖
标题:各位大侠求教!!C#listView赋值另一窗体的多个textBox问题
只看楼主 加入收藏
alina4122015
Rank: 2
等 级:论坛游民
帖 子:27
专家分:31
注 册:2013-11-4
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
各位大侠求教!!C#listView赋值另一窗体的多个textBox问题
想做一个数据库信息修改的功能
 private void FillMobile(ArrayList mList)
        {
            listView1.Items.Clear();
            foreach (Mobile m in mList)
            {
                ListViewItem Item = listView1.Items.Add(m.SimNo);
                Item.SubItems.Add(Convert.ToString(m.StartHour));
                Item.SubItems.Add(Convert.ToString(m.StartMinute));
                Item.SubItems.Add(Convert.ToString(m.EndHour));
                Item.SubItems.Add(Convert.ToString(m.EndMinute));
                Item.SubItems.Add(Convert.ToString(m.RetSpan));
            }

            label2.Text = string.Format("共计 {0} 条记录", listView1.Items.Count);
        }
这是我从数据库以创建集合形式写入listView,因为有有6个列,实际焦点只能在SimNo上,点击焦点,单击修改按键跳出新窗体,如何让新窗体6个textBox中赋值呢
搜索更多相关主题的帖子: private Mobile 数据库 信息 
2013-11-05 09:22
shangsharon
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
威 望:7
帖 子:221
专家分:1261
注 册:2012-3-25
收藏
得分:20 
最简单实用的是在跳出的窗体中添加一个构造函数,
例如:public EditForm(string s1,string s2,.....,string s6)
        {
             TextBox1.Text=s1;
             TextBox2.Text=s2;
             ......
             TextBox6.Text=s6;
        }

当你单击修改按键时代码改为:
//获取6列的文本,分别赋值给s1,s2,s3.....
EditForm f = new EditForm(s1,s2,.....,s6)
2013-11-05 16:15
namzyq
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-11-5
收藏
得分:0 
刚先入学,进来看看,新手,请大家多指教。
2013-11-05 18:44
alina4122015
Rank: 2
等 级:论坛游民
帖 子:27
专家分:31
注 册:2013-11-4
收藏
得分:0 
以下是引用shangsharon在2013-11-5 16:15:57的发言:

最简单实用的是在跳出的窗体中添加一个构造函数,
例如:public EditForm(string s1,string s2,.....,string s6)
        {
             TextBox1.Text=s1;
             TextBox2.Text=s2;
             ......
             TextBox6.Text=s6;
        }

当你单击修改按键时代码改为:
//获取6列的文本,分别赋值给s1,s2,s3.....
EditForm f = new EditForm(s1,s2,.....,s6)


还是挺感谢的!我是这样写的,也可以
FORM1
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                ListViewItem Item = listView1.SelectedItems[0];

                string simNo = Item.SubItems[0].Text;
                string startHoure = Item.SubItems[1].Text;
                string startMinute = Item.SubItems[2].Text;
                string endHoure = Item.SubItems[3].Text;
                string endMinute = Item.SubItems[4].Text;
                string retSpan = Item.SubItems[5].Text;

                FrmSimChange changesimno = new FrmSimChange();
                changesimno.CSimNo = simNo;
                changesimno.CStartHour = int.Parse(startHoure);
                changesimno.CStartMinute = int.Parse(startMinute);
                changesimno.CEndHour = int.Parse(endHoure);
                changesimno.CEndMinute = int.Parse(endMinute);
                changesimno.CRetSpan = int.Parse(retSpan);
                if (changesimno.ShowDialog() == DialogResult.OK)
                {
                    Item.SubItems[1].Text = changesimno.CStartHour.ToString();
                    Item.SubItems[2].Text = changesimno.CStartMinute.ToString();
                    Item.SubItems[3].Text = changesimno.CEndHour.ToString();
                    Item.SubItems[4].Text = changesimno.CEndMinute.ToString();
                    Item.SubItems[5].Text = changesimno.CRetSpan.ToString();
                }
            }
            catch
            {
                MessageBox.Show("请选择需要修改的号码");
                return;
            }
            finally
            {
            }
        }

FORM2
    public partial class FrmSimChange : Form
    {
        public FrmSimChange()
        {
            InitializeComponent();
        }

        private void FrmSimChange_Load(object sender, EventArgs e)
        {
        }

        public string CSimNo
        {
            get
            {
                return tBsnc.Text;
            }
            set
            {
                tBsnc.Text = value;
            }
        }
        public int CStartHour
        {
            get
            {
                return int.Parse(tBshc.Text);
            }
            set
            {
                tBshc.Text = Convert.ToString(value);
            }
        }
        public int CStartMinute
        {
            get
            {
                return int.Parse(tBsmc.Text);
            }
            set
            {
                tBsmc.Text = Convert.ToString(value);
            }
        }
        public int CEndHour
        {
            get
            {
                return int.Parse(tBehc.Text);
            }
            set
            {
                tBehc.Text = Convert.ToString(value);
            }
        }
        public int CEndMinute
        {
            get
            {
                return int.Parse(tBemc.Text);
            }
            set
            {
                tBemc.Text = Convert.ToString(value);
            }
        }
        public int CRetSpan
        {
            get
            {
                return int.Parse(tBrsc.Text);
            }
            set
            {
                tBrsc.Text = Convert.ToString(value);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }
    }
2013-11-05 19:39
快速回复:各位大侠求教!!C#listView赋值另一窗体的多个textBox问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.069309 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved