我的新公司:Janky A ## Solutions,Inc。申请现已被接受。 [英] My New Company: Janky A## Solutions, Inc. applications now being accepted.

查看:75
本文介绍了我的新公司:Janky A ## Solutions,Inc。申请现已被接受。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,在我开始之前,首先,这是一篇帮助文章。我是

只是感到震惊我没有想到一个解决方案或者无法在网上找到一个

all。所以我想我会在这里写一个快速的模糊,在某人想要

在博客上发布它所以它可以被蜘蛛,感觉自由。我还没有一个

,应该可以设置一个。


好​​吧......现在我在几个星期前提出这个问题了有点把它放在

的方式,但现在它已成为一个问题再次与我开发的应用程序。我相信Armin也在寻找一个解决方案,并且有一个b $ b,但我们都同意这有点粗糙。好吧...我使用相同的

想法,只是有点不同。也许如果它写出来的人会理解的话。


现在......我到底在说什么?臭名昭着的<选择无>里面

一个数据绑定组合框。有多少次你被一个

非必填字段惹恼了,但是dot net不支持将数据添加到数据包中

列表控件!


所以,我的好朋友这是一个快速而肮脏的方法,我会在路上解释(不久)。希望它能帮助所有人。


好​​吧,关于ComboBox的一些信息。 1,它并不像我们所有人那样愚蠢

想,事实上,它非常巧妙(好吧,点网本身的数据绑定

非常酷,这只是让它变得更好)。 Combobox只关心2

接口的绑定(很像大多数事情)IList,或IListSource。


所以知道这一点,并知道大量的可能

的类实现IList我们可以开始讨论。


在我的例子中,我们将为我们的IList使用System.Data.DataTable类

提供商。并使用DataRow作为我们的对象添加到IList / IListSource

集合。我发现这些是最简单的,因为一切都是根据需要实现的
(你可以自己动手,但最后,你的行动

基本上可以得到一个数据流具有较少的属性/方法。它已经上涨了




要记住的重要一点是,Combobox关心2件事情(如同

you)DisplayMember和ValueMember。这些是由组合框从我们的列表源中的

属性中提取的。在我们的例子中,他们

代表数据行的字段,或IList上的索引器的属性

(即IList(0)(fieldName))


所以我们声明一个无类型的数据行,数据表


Dim dr作为DataRow

Dim dt作为新的DataTable( MyTable)


表格的名称在这里并不重要,我是出于习惯而做的。


然后,将你的列添加到数据表中,以便组合框结合到上面。


dt.Columns.Add(New DataColumn(" DisplayMember",getType(String)))

dt.Columns.Add(New DataColumn(" ValueMember",getType(Integer)))

数据类型对于valuemember并不重要,因为它可能是一个

对象(rmember但是,如果它是一个对象并且你想使用

SelectedValue你必须实现IComparable)


首先,我们将继续添加我们的无。行。


dr = dt.NewRow()

dr(" DisplayMember")="< none ...>"

dr(" ValueMember")= 0

dt.Rows.Add(dr)


这将我们的第一行添加到表中,显然没有绑定到数据集或

任何适配器,所以没有更新担心。然后我把我希望数据关闭的数据集

加载到组合框中并加载到我的表中


Dim cRow as DataRow


为myDataSet.Tables中的每个cRow(" yourTableHere")

dr = dt.NewRow()

dr(" DisplayMember") = cRow(" PropertyName")

dr(" ValueMember")= cRow(" OtherPropertyName")

dt.Rows.Add(dr)

next


最后,将你的源绑定到你的组合框。


me.myComboBox.DataSource = dt

me.myComboBox.DisplayMember =" DisplayMember"

me.myComboBox.ValueMember =" ValueMember"


显然,您可以替换DisplayMember无论你想要什么,价值会员都可以获得

,但这只是一个例子。就是这样。你将获得
绑定并准备就绪。


有点笨拙,但它可以毫无疑问地完成工作。


希望它有所帮助。


CJ

解决方案

我肯定在这里错过了一些东西因为我昨晚有宿醉

但是当你做一个DataAdapter.Update(你的DT)会发生什么?


OHM


CJ Taylor写道:

好吧,在我开始之前,首先,这是一篇帮助文章。
我很震惊我没想到解决方案或根本无法在网络上找到一个解决方案。所以我想我会在这里写一个快速的模糊,
有人想在博客上发布它,所以它可以被蜘蛛,感觉自由。我还没有一个,应该可以设置一个。

好吧......现在几个星期前我把这个问题提了起来,有点把它放在路边但是现在它已成为我正在开发的
应用程序的问题。我相信Armin也在寻找一个
解决方案,并且有一个,但我们都同意它有点粗糙。
好的...我使用相同的想法,只是有点不同。并且
也许如果它写出来的人会理解的。

现在......我到底在说什么?臭名昭着的< select none>
在数据绑定组合框内。有多少次你被一个非必需的领域惹恼了,但是dot net不支持将数据添加到数据绑定列表控件中!

所以,我的好朋友这个这是一种快速而肮脏的方式,我会在路上解释(不久)。希望它能帮助每个人。

好的,有关ComboBox的一些信息。 1,它并不像我们所有人所认为的那样愚蠢,事实上,它非常巧妙(好吧,点网中的数据绑定本身非常酷,这只是让它变得更好)。 Combobox只关心绑定中的2个接口(很像大多数东西)IList,或者IListSource。

知道这一点,并且知道大量的类
可能会实现IList,我们可以开始讨论。

在我的例子中,我们将使用System.Data.DataTable类来构建我们的IList提供程序。并使用DataRow作为我们的对象添加到IList / IListSource集合中。我发现这些是最简单的因为一切都是根据需要实现的(你可以自己动手,但是最后,你的基本上会得到一个具有较少属性的数据行) /方法。这取决于你)

要记住的重要一点是,Combobox关心DisplayMember和ValueMember两件事(如你所知)。这些是由组合框从我们的列表源中的
属性中提取的。在我们的例子中,它们代表数据行的字段,或IList上的索引器的属性(即IList(0)(fieldName))

所以我们宣布一个无类型的数据行,数据表

Dim dr as DataRow
Dim dt as new DataTable(MyTable)

表的名称是'n'在这里很重要,我是出于习惯而做的。

然后,将你的列添加到数据表中,以便将组合框绑定到。

dt.Columns.Add(New DataColumn(" DisplayMember",getType(String)))
dt.Columns.Add(New DataColumn(" ValueMember",getType(Integer)))

数据类型不是对于valuemember非常重要,因为它可以是一个对象(rmember,如果它是一个对象并且你想使用
SelectedValue你必须实现IComparable)

首先,我们将继续添加我们的无行。

dr = dt.NewRow()
dr(" DisplayMember")="< none ...>"
dr(" ValueMember")= 0
dt.Rows.Add(dr)

这会将我们的第一行添加到表中,显然没有绑定到
数据集或任何适配器,所以没有更新担心。然后我把我希望数据的
数据集加载到组合框中并加载到我的表格中

Dim cRow as DataRow

myDataSet.Tables中的每个cRow(" yourTableHere")
dr = dt.NewRow()
dr(" DisplayMember")= cRow(" PropertyName")
dr(" ValueMember")= cRow(" OtherPropertyName")
dt.Rows.Add(dr)
next

最后,将你的源绑定到你的组合框。

me.myComboBox.DataSource = dt
me.myComboBox.DisplayMember =" DisplayMember"
me.myComboBox.ValueMember =" ValueMember"

显然,你可以用你想要的任何东西替换DisplayMember和ValueMember vlaues,但这只是一个例子。就是这样。你将会受到约束和准备。

有点笨拙,但它完成了工作而没有任何问题。

希望它有所帮助。

CJ




-

最诚挚的问候 - OHM


O_H_M {at} BTInternet {dot} com


重点...你不要。


=)

One Handed Man [OHM#]" < O_H_M {在} BTInternet {点} COM>在消息中写道

新闻:eJ ************** @ TK2MSFTNGP09.phx.gbl ...

我很有信心我错过了一些东西,因为我昨晚有宿醉
但是当你做一个DataAdapter.Update(你的DT)会发生什么?

OHM

CJ Taylor写道:

好吧,在我开始之前,首先,这是一篇帮助文章。
我很震惊我没有想到解决方案或者不能在网上找到一个。所以我想我会在这里写一个快速的模糊,
有人想在博客上发布它,所以它可以被蜘蛛,感觉自由。我还没有一个,应该可以设置一个。

好吧......现在几个星期前我把这个问题提了起来,有点把它放在路边但是现在它已成为我正在开发的
应用程序的问题。我相信Armin也在寻找一个
解决方案,并且有一个,但我们都同意它有点粗糙。
好的...我使用相同的想法,只是有点不同。并且
也许如果它写出来的人会理解的。

现在......我到底在说什么?臭名昭着的< select none>
在数据绑定组合框内。有多少次你被一个非必需的领域惹恼了,但是dot net不支持将数据添加到数据绑定列表控件中!

所以,我的好朋友这个这是一种快速而肮脏的方式,我会在路上解释(不久)。希望它能帮助每个人。

好的,有关ComboBox的一些信息。 1,它并不像我们所有人所认为的那样愚蠢,事实上,它非常巧妙(好吧,点网中的数据绑定本身非常酷,这只是让它变得更好)。 Combobox只关心绑定中的2个接口(很像大多数东西)IList,或者IListSource。

知道这一点,并且知道大量的类
可能会实现IList,我们可以开始讨论。

在我的例子中,我们将使用System.Data.DataTable类来构建我们的IList提供程序。并使用DataRow作为我们的对象添加到IList / IListSource集合中。我发现这些是最简单的因为一切都是根据需要实现的(你可以自己动手,但是最后,你的基本上会得到一个具有较少属性的数据行) /方法。这取决于你)

要记住的重要一点是,Combobox关心DisplayMember和ValueMember两件事(如你所知)。这些是由组合框从我们的列表源中的
属性中提取的。在我们的例子中,它们代表数据行的字段,或IList上的索引器的属性(即IList(0)(fieldName))

所以我们宣布一个无类型的数据行,数据表

Dim dr as DataRow
Dim dt as new DataTable(MyTable)

表的名称是'n'在这里很重要,我是出于习惯而做的。

然后,将你的列添加到数据表中,以便将组合框绑定到。

dt.Columns.Add(New DataColumn(" DisplayMember",getType(String)))
dt.Columns.Add(New DataColumn(" ValueMember",getType(Integer)))

数据类型不是对于valuemember非常重要,因为它可以是一个对象(rmember,如果它是一个对象并且你想使用
SelectedValue你必须实现IComparable)

首先,我们将继续添加我们的无行。

dr = dt.NewRow()
dr(" DisplayMember")="< none ...>"
dr(" ValueMember")= 0
dt.Rows.Add(dr)

这会将我们的第一行添加到表中,显然没有绑定到
数据集或任何适配器,所以没有更新担心。然后我把我希望数据的
数据集加载到组合框中并加载到我的表格中

Dim cRow as DataRow

myDataSet.Tables中的每个cRow(" yourTableHere")
dr = dt.NewRow()
dr(" DisplayMember")= cRow(" PropertyName")
dr(" ValueMember")= cRow(" OtherPropertyName")
dt.Rows.Add(dr)
next

最后,将你的源绑定到你的组合框。

me.myComboBox.DataSource = dt
me.myComboBox.DisplayMember =" DisplayMember"
me.myComboBox.ValueMember =" ValueMember"

显然,你可以用你想要的任何东西替换DisplayMember和ValueMember vlaues,但这只是一个例子。就是这样。你将会受到约束和准备。

有点笨拙,但它完成了工作而没有任何问题。

希望它有所帮助。

CJ



- 最诚挚的问候 - OHM

O_H_M {at} BTInternet {dot} com



或...在。< none>上添加.AcceptChanges数据行。 =)


One Handed Man [OHM#]" < O_H_M {在} BTInternet {点} COM>在消息中写道

新闻:eJ ************** @ TK2MSFTNGP09.phx.gbl ...

我很有信心我错过了一些东西,因为我昨晚有宿醉
但是当你做一个DataAdapter.Update(你的DT)会发生什么?

OHM

CJ Taylor写道:

好吧,在我开始之前,首先,这是一篇帮助文章。
我很震惊我没有想到解决方案或者不能在网上找到一个。所以我想我会在这里写一个快速的模糊,
有人想在博客上发布它,所以它可以被蜘蛛,感觉自由。我还没有一个,应该可以设置一个。

好吧......现在几个星期前我把这个问题提了起来,有点把它放在路边但是现在它已成为我正在开发的
应用程序的问题。我相信Armin也在寻找一个
解决方案,并且有一个,但我们都同意它有点粗糙。
好的...我使用相同的想法,只是有点不同。并且
也许如果它写出来的人会理解的。

现在......我到底在说什么?臭名昭着的< select none>
在数据绑定组合框内。有多少次你被一个非必需的领域惹恼了,但是dot net不支持将数据添加到数据绑定列表控件中!

所以,我的好朋友这个这是一种快速而肮脏的方式,我会在路上解释(不久)。希望它能帮助每个人。

好的,有关ComboBox的一些信息。 1,它并不像我们所有人所认为的那样愚蠢,事实上,它非常巧妙(好吧,点网中的数据绑定本身非常酷,这只是让它变得更好)。 Combobox只关心绑定中的2个接口(很像大多数东西)IList,或者IListSource。

知道这一点,并且知道大量的类
可能会实现IList,我们可以开始讨论。

在我的例子中,我们将使用System.Data.DataTable类来构建我们的IList提供程序。并使用DataRow作为我们的对象添加到IList / IListSource集合中。我发现这些是最简单的因为一切都是根据需要实现的(你可以自己动手,但是最后,你的基本上会得到一个具有较少属性的数据行) /方法。这取决于你)

要记住的重要一点是,Combobox关心DisplayMember和ValueMember两件事(如你所知)。这些是由组合框从我们的列表源中的
属性中提取的。在我们的例子中,它们代表数据行的字段,或IList上的索引器的属性(即IList(0)(fieldName))

所以我们宣布一个无类型的数据行,数据表

Dim dr as DataRow
Dim dt as new DataTable(MyTable)

表的名称是'n'在这里很重要,我是出于习惯而做的。

然后,将你的列添加到数据表中,以便将组合框绑定到。

dt.Columns.Add(New DataColumn(" DisplayMember",getType(String)))
dt.Columns.Add(New DataColumn(" ValueMember",getType(Integer)))

数据类型不是对于valuemember非常重要,因为它可以是一个对象(rmember,如果它是一个对象并且你想使用
SelectedValue你必须实现IComparable)

首先,我们将继续添加我们的无行。

dr = dt.NewRow()
dr(" DisplayMember")="< none ...>"
dr(" ValueMember")= 0
dt.Rows.Add(dr)

这会将我们的第一行添加到表中,显然没有绑定到
数据集或任何适配器,所以没有更新担心。然后我把我希望数据的
数据集加载到组合框中并加载到我的表格中

Dim cRow as DataRow

myDataSet.Tables中的每个cRow(" yourTableHere")
dr = dt.NewRow()
dr(" DisplayMember")= cRow(" PropertyName")
dr(" ValueMember")= cRow(" OtherPropertyName")
dt.Rows.Add(dr)
next

最后,将你的源绑定到你的组合框。

me.myComboBox.DataSource = dt
me.myComboBox.DisplayMember =" DisplayMember"
me.myComboBox.ValueMember =" ValueMember"

显然,你可以用你想要的任何东西替换DisplayMember和ValueMember vlaues,但这只是一个例子。就是这样。你将会受到约束和准备。

有点笨拙,但它完成了工作而没有任何问题。

希望它有所帮助。

CJ



- 最诚挚的问候 - OHM

O_H_M {at} BTInternet {dot} com



Alright before I get started, first of all, this is a help article. I''m
just shocked I didn''t think of a solution or couldn''t find one on the web at
all. So I figured I would write a quick blurb on here, in someone wants to
post it on there blog so it can be spidered, feel free. I don''t have one
yet, should probably set one up.

Alright... Now I brought this issue up a few weeks ago and kinda put it to
the way side but now it has become an issue again with an application I am
developing. I believe Armin was looking for a solution as well, and had
one, but we both agreed it was a bit rough. Well sorta... I use the same
idea, just a little different. And maybe if its written out people will
understand.

Now... what the hell am I talking about? The infamous <select none> inside
a databound combo box. how many times have you been annoyed by a
non-required field but dot net doesn''t support adding items to databound
list controls!

So, my fine friends this is a quick and dirty way to do it, which I''ll
explain on the way (its not long). And hopefully it will help everyone out.

Alright, a little info about ComboBox. 1, its not as dumb as we all
thought, in fact, its quite ingenious (well, databinding in dot net itself
is pretty cool, this just makes it better). Combobox only cares about 2
interfaces in binding (much like most things) IList, or IListSource.

So knowing this, and knowing the the massive amount of classes that probably
implement IList we can start coming to conculsions.

In my example, we are going to use System.Data.DataTable class for our IList
provider. And use a DataRow as our Object to add to the IList/IListSource
Collection. I find these to be the easiest ones because everything is
implemented as needed (you could roll your own, but in the end, your going
to basically come up with a datarow with less properties/methods. It''s up
to you)

The important thing to remember is, Combobox cares about 2 things (as do
you) the DisplayMember and the ValueMember. These are pulled from
Properties within our list source by the combobox. In our case, they
represent the fields of the datarow, or a property of the indexer on IList
(i.e. IList(0)("fieldName"))

So we declare a untyped datarow, and datatable

Dim dr as DataRow
Dim dt as new DataTable("MyTable")

the name of the table isn''t important here, I do it out of habit.

Then, add your columns to the datatable for the combobox to bind onto.

dt.Columns.Add(New DataColumn("DisplayMember", getType(String)))
dt.Columns.Add(New DataColumn("ValueMember", getType(Integer)))

Datatypes aren''t really important on the valuemember since it can be an
object (rmember though, if it is an object and you wanted to use
SelectedValue you have to implement IComparable)

First, we are going to go ahead and add in our "none" row.

dr = dt.NewRow()
dr("DisplayMember") = "< none ... >"
dr("ValueMember") = 0
dt.Rows.Add(dr)

this adds our first row to the table, obviously not bound to a dataset or
any adapter, so no update worries. I then take the dataset I want data off
of to load into the combobox and load it into my table

Dim cRow as DataRow

for each cRow in myDataSet.Tables("yourTableHere")
dr = dt.NewRow()
dr("DisplayMember") = cRow("PropertyName")
dr("ValueMember") = cRow("OtherPropertyName")
dt.Rows.Add (dr)
next

Finally, bind your source to your combobox.

me.myComboBox.DataSource = dt
me.myComboBox.DisplayMember = "DisplayMember"
me.myComboBox.ValueMember = "ValueMember"

Obviously, you can replace DisplayMember and ValueMember vlaues with
whatever you want, but this is just an example. And thats it. You will be
bound and ready.

A little janky, but it gets the job done with no questions.

Hope it helps.

CJ

解决方案

I''m sure ive missed something here as I have a hangover from last night
but what happens when you do a DataAdapter.Update( Your DT )?

OHM

CJ Taylor wrote:

Alright before I get started, first of all, this is a help article.
I''m just shocked I didn''t think of a solution or couldn''t find one on
the web at all. So I figured I would write a quick blurb on here, in
someone wants to post it on there blog so it can be spidered, feel
free. I don''t have one yet, should probably set one up.

Alright... Now I brought this issue up a few weeks ago and kinda put
it to the way side but now it has become an issue again with an
application I am developing. I believe Armin was looking for a
solution as well, and had one, but we both agreed it was a bit rough.
Well sorta... I use the same idea, just a little different. And
maybe if its written out people will understand.

Now... what the hell am I talking about? The infamous <select none>
inside a databound combo box. how many times have you been annoyed
by a non-required field but dot net doesn''t support adding items to
databound list controls!

So, my fine friends this is a quick and dirty way to do it, which I''ll
explain on the way (its not long). And hopefully it will help
everyone out.

Alright, a little info about ComboBox. 1, its not as dumb as we all
thought, in fact, its quite ingenious (well, databinding in dot net
itself is pretty cool, this just makes it better). Combobox only
cares about 2 interfaces in binding (much like most things) IList, or
IListSource.

So knowing this, and knowing the the massive amount of classes that
probably implement IList we can start coming to conculsions.

In my example, we are going to use System.Data.DataTable class for
our IList provider. And use a DataRow as our Object to add to the
IList/IListSource Collection. I find these to be the easiest ones
because everything is implemented as needed (you could roll your own,
but in the end, your going to basically come up with a datarow with
less properties/methods. It''s up to you)

The important thing to remember is, Combobox cares about 2 things (as
do you) the DisplayMember and the ValueMember. These are pulled from
Properties within our list source by the combobox. In our case, they
represent the fields of the datarow, or a property of the indexer on
IList (i.e. IList(0)("fieldName"))

So we declare a untyped datarow, and datatable

Dim dr as DataRow
Dim dt as new DataTable("MyTable")

the name of the table isn''t important here, I do it out of habit.

Then, add your columns to the datatable for the combobox to bind onto.

dt.Columns.Add(New DataColumn("DisplayMember", getType(String)))
dt.Columns.Add(New DataColumn("ValueMember", getType(Integer)))

Datatypes aren''t really important on the valuemember since it can be
an object (rmember though, if it is an object and you wanted to use
SelectedValue you have to implement IComparable)

First, we are going to go ahead and add in our "none" row.

dr = dt.NewRow()
dr("DisplayMember") = "< none ... >"
dr("ValueMember") = 0
dt.Rows.Add(dr)

this adds our first row to the table, obviously not bound to a
dataset or any adapter, so no update worries. I then take the
dataset I want data off of to load into the combobox and load it into
my table

Dim cRow as DataRow

for each cRow in myDataSet.Tables("yourTableHere")
dr = dt.NewRow()
dr("DisplayMember") = cRow("PropertyName")
dr("ValueMember") = cRow("OtherPropertyName")
dt.Rows.Add (dr)
next

Finally, bind your source to your combobox.

me.myComboBox.DataSource = dt
me.myComboBox.DisplayMember = "DisplayMember"
me.myComboBox.ValueMember = "ValueMember"

Obviously, you can replace DisplayMember and ValueMember vlaues with
whatever you want, but this is just an example. And thats it. You
will be bound and ready.

A little janky, but it gets the job done with no questions.

Hope it helps.

CJ



--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com


Thats the point... you dont.

=)

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:eJ**************@TK2MSFTNGP09.phx.gbl...

I''m sure ive missed something here as I have a hangover from last night
but what happens when you do a DataAdapter.Update( Your DT )?

OHM

CJ Taylor wrote:

Alright before I get started, first of all, this is a help article.
I''m just shocked I didn''t think of a solution or couldn''t find one on
the web at all. So I figured I would write a quick blurb on here, in
someone wants to post it on there blog so it can be spidered, feel
free. I don''t have one yet, should probably set one up.

Alright... Now I brought this issue up a few weeks ago and kinda put
it to the way side but now it has become an issue again with an
application I am developing. I believe Armin was looking for a
solution as well, and had one, but we both agreed it was a bit rough.
Well sorta... I use the same idea, just a little different. And
maybe if its written out people will understand.

Now... what the hell am I talking about? The infamous <select none>
inside a databound combo box. how many times have you been annoyed
by a non-required field but dot net doesn''t support adding items to
databound list controls!

So, my fine friends this is a quick and dirty way to do it, which I''ll
explain on the way (its not long). And hopefully it will help
everyone out.

Alright, a little info about ComboBox. 1, its not as dumb as we all
thought, in fact, its quite ingenious (well, databinding in dot net
itself is pretty cool, this just makes it better). Combobox only
cares about 2 interfaces in binding (much like most things) IList, or
IListSource.

So knowing this, and knowing the the massive amount of classes that
probably implement IList we can start coming to conculsions.

In my example, we are going to use System.Data.DataTable class for
our IList provider. And use a DataRow as our Object to add to the
IList/IListSource Collection. I find these to be the easiest ones
because everything is implemented as needed (you could roll your own,
but in the end, your going to basically come up with a datarow with
less properties/methods. It''s up to you)

The important thing to remember is, Combobox cares about 2 things (as
do you) the DisplayMember and the ValueMember. These are pulled from
Properties within our list source by the combobox. In our case, they
represent the fields of the datarow, or a property of the indexer on
IList (i.e. IList(0)("fieldName"))

So we declare a untyped datarow, and datatable

Dim dr as DataRow
Dim dt as new DataTable("MyTable")

the name of the table isn''t important here, I do it out of habit.

Then, add your columns to the datatable for the combobox to bind onto.

dt.Columns.Add(New DataColumn("DisplayMember", getType(String)))
dt.Columns.Add(New DataColumn("ValueMember", getType(Integer)))

Datatypes aren''t really important on the valuemember since it can be
an object (rmember though, if it is an object and you wanted to use
SelectedValue you have to implement IComparable)

First, we are going to go ahead and add in our "none" row.

dr = dt.NewRow()
dr("DisplayMember") = "< none ... >"
dr("ValueMember") = 0
dt.Rows.Add(dr)

this adds our first row to the table, obviously not bound to a
dataset or any adapter, so no update worries. I then take the
dataset I want data off of to load into the combobox and load it into
my table

Dim cRow as DataRow

for each cRow in myDataSet.Tables("yourTableHere")
dr = dt.NewRow()
dr("DisplayMember") = cRow("PropertyName")
dr("ValueMember") = cRow("OtherPropertyName")
dt.Rows.Add (dr)
next

Finally, bind your source to your combobox.

me.myComboBox.DataSource = dt
me.myComboBox.DisplayMember = "DisplayMember"
me.myComboBox.ValueMember = "ValueMember"

Obviously, you can replace DisplayMember and ValueMember vlaues with
whatever you want, but this is just an example. And thats it. You
will be bound and ready.

A little janky, but it gets the job done with no questions.

Hope it helps.

CJ



--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com



or... add .AcceptChanges on the <none> data row. =)

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:eJ**************@TK2MSFTNGP09.phx.gbl...

I''m sure ive missed something here as I have a hangover from last night
but what happens when you do a DataAdapter.Update( Your DT )?

OHM

CJ Taylor wrote:

Alright before I get started, first of all, this is a help article.
I''m just shocked I didn''t think of a solution or couldn''t find one on
the web at all. So I figured I would write a quick blurb on here, in
someone wants to post it on there blog so it can be spidered, feel
free. I don''t have one yet, should probably set one up.

Alright... Now I brought this issue up a few weeks ago and kinda put
it to the way side but now it has become an issue again with an
application I am developing. I believe Armin was looking for a
solution as well, and had one, but we both agreed it was a bit rough.
Well sorta... I use the same idea, just a little different. And
maybe if its written out people will understand.

Now... what the hell am I talking about? The infamous <select none>
inside a databound combo box. how many times have you been annoyed
by a non-required field but dot net doesn''t support adding items to
databound list controls!

So, my fine friends this is a quick and dirty way to do it, which I''ll
explain on the way (its not long). And hopefully it will help
everyone out.

Alright, a little info about ComboBox. 1, its not as dumb as we all
thought, in fact, its quite ingenious (well, databinding in dot net
itself is pretty cool, this just makes it better). Combobox only
cares about 2 interfaces in binding (much like most things) IList, or
IListSource.

So knowing this, and knowing the the massive amount of classes that
probably implement IList we can start coming to conculsions.

In my example, we are going to use System.Data.DataTable class for
our IList provider. And use a DataRow as our Object to add to the
IList/IListSource Collection. I find these to be the easiest ones
because everything is implemented as needed (you could roll your own,
but in the end, your going to basically come up with a datarow with
less properties/methods. It''s up to you)

The important thing to remember is, Combobox cares about 2 things (as
do you) the DisplayMember and the ValueMember. These are pulled from
Properties within our list source by the combobox. In our case, they
represent the fields of the datarow, or a property of the indexer on
IList (i.e. IList(0)("fieldName"))

So we declare a untyped datarow, and datatable

Dim dr as DataRow
Dim dt as new DataTable("MyTable")

the name of the table isn''t important here, I do it out of habit.

Then, add your columns to the datatable for the combobox to bind onto.

dt.Columns.Add(New DataColumn("DisplayMember", getType(String)))
dt.Columns.Add(New DataColumn("ValueMember", getType(Integer)))

Datatypes aren''t really important on the valuemember since it can be
an object (rmember though, if it is an object and you wanted to use
SelectedValue you have to implement IComparable)

First, we are going to go ahead and add in our "none" row.

dr = dt.NewRow()
dr("DisplayMember") = "< none ... >"
dr("ValueMember") = 0
dt.Rows.Add(dr)

this adds our first row to the table, obviously not bound to a
dataset or any adapter, so no update worries. I then take the
dataset I want data off of to load into the combobox and load it into
my table

Dim cRow as DataRow

for each cRow in myDataSet.Tables("yourTableHere")
dr = dt.NewRow()
dr("DisplayMember") = cRow("PropertyName")
dr("ValueMember") = cRow("OtherPropertyName")
dt.Rows.Add (dr)
next

Finally, bind your source to your combobox.

me.myComboBox.DataSource = dt
me.myComboBox.DisplayMember = "DisplayMember"
me.myComboBox.ValueMember = "ValueMember"

Obviously, you can replace DisplayMember and ValueMember vlaues with
whatever you want, but this is just an example. And thats it. You
will be bound and ready.

A little janky, but it gets the job done with no questions.

Hope it helps.

CJ



--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com



这篇关于我的新公司:Janky A ## Solutions,Inc。申请现已被接受。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆