WPF ListView 插入Combox和TextBox取值和赋值

WPF ListView 插入Combox和TextBox取值和赋值,第1张

第一种方法

DataTable dt = new DataTable()

dt.Columns.Add( "name" )

dt.Columns.Add( "value" )

DataRow dr = dt.NewRow()

dr[0] = "活动"

dr[1] = "1"

dt.Rows.Add(dr)DataRow dr1 = dt.NewRow()

dr1[0] = "生活"

dr1[1] = "2"

dt.Rows.Add(dr1)

this .comboBox1.DataSource = dt

this .comboBox1.DisplayMember = "name"

this .comboBox1.ValueMember = "value"

//调用方法:

//string _value = comboBox1.SelectedValue.ToString()

第二种:

//首先添加一个ComboBoxItem类

public class ComboBoxItem

{

private string _text = null

private object _value = null

public string Text

{ get {

return this ._text

} set {

this ._text = value

} }

public object Value

{ get {

return this ._value

} set {

this ._value = value

} }

public override string ToString()

{

return this ._text

} }

// 赋值方法

ComboBoxItem newitem = new ComboBoxItem()

newitem.Text = "男"

newitem.Value = "1"

ComboBoxItem newitem1 = new ComboBoxItem()

newitem1.Text = "女"

newitem1.Value = "0"

com_sex.Items.Add(newitem)

com_sex.Items.Add(newitem1)

// 调用方法:

ComboBoxItem sex_item = (ComboBoxItem)com_sex.SelectedItem

int com_sex_value = Convert.ToInt32(sex_item.Value)

string _Name = sex_item.Text

第三种:

//首先添加一个SetCls类

publicclassSetCls

{

privatestringID

privatestringNAME

publicSetCls( stringpid, stringpName)

{

this .ID =pid

this .NAME =pName

}

publicstringpID

{

get { returnID}

}

publicstringpName

{

get { returnNAME}

} }

// 赋值方法:(使用ArrayList 要先引用命名空间using System.Collections)

ArrayList lists = new ArrayList()

lists .Add( new SetCls ( "1" , "活动" ))

lists .Add( new SetCls ( "2" , "生活" ))

this .COMBOX.DisplayMember = "pID"

this .COMBOX.ValueMember = "pName"

this .COMBOX.DataSource = lists

// 调用方法:

string com_sex_value = COMBOX.SelectedValue.ToString()

我用DataSet填充的数据库中的内容(我这个是直接赋值,并不像上面三个添加值给ComBox)

DataSet ds_zubie = new DataSet()

da = new SqlDataAdapter(sql_zubie, PublicDB.DBzbw)

da.Fill(ds_zubie, "zubie" )

com_paidan.DataSource = ds_zubie.Tables[ "zubie" ].DefaultView//绑定数据源

com_paidan.ValueMember = "zubie_id" //赋值Value

com_paidan.DisplayMember = "zubie_name" //赋值显示名称

//调用方法:

string com_zubie_id = com_paidan.SelectedValue.ToString()

编辑列,把需要的那列转为模版,然后可以自己在里面放想放的东西了。

<ItemTemplate>

<asp:Label></asp:Label>

</ItemTemplate>

<EditItemTemplate>

<asp:DropDownList></asp:DropDownList>

</EditItemTemplate>

你的意思是不是:listview为一个组(1,2,3),combobox为另一个数组(01,02,03) 当选listview(1) combox(1),当选listview(2) combox(2) 是这个工作方案吗? 如果是,那通过我的思维方式就可以解决了噻! 在listview中的数据一定要排序了噻!这个顺序和combox中的排序方法一样,把数据添加到combox.会把数据库中的内容添加到combox中噻?那就好说了! 然后选择n行,就调用combox(n-1).这是因为listview的头就标题噻。 调试一下就行了。这只是方法之一。主要是打字太慢,不然可以说得更细些!


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/bake/11221263.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存