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 17 1064
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
Hmm, doesent this slow things down a tad ?
As far as I remember, I think I managed to get around this by checking for a
updat event on the datatable or some such event and then inserting the
<Select Value> in the front of the ComboBox each time.
Mind you, its a bit hazy now.
Regards - OHM
CJ Taylor wrote: 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
--
Best Regards - OHM
O_H_M{at}BTInternet{dot}com
> 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
Is that the reason, I was just thinking before reading this message "what is
that OHM super active this day".
Before you write it, you are of course always active only today super
active.
:-))
Cor
What??
The bloody dutch...
=)
Nothin' but love for ya.
Plutonically...
"Cor" <no*@non.com> wrote in message
news:%2****************@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 Is that the reason, I was just thinking before reading this message "what
is that OHM super active this day".
Before you write it, you are of course always active only today super active.
:-))
Cor
And this handled the None issue? Forgive me I just don't see where your
going with this.
I understand your hazy, so that could be the reason. =)
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl... Hmm, doesent this slow things down a tad ?
As far as I remember, I think I managed to get around this by checking for
a updat event on the datatable or some such event and then inserting the <Select Value> in the front of the ComboBox each time.
Mind you, its a bit hazy now.
Regards - OHM CJ Taylor wrote: 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
-- Best Regards - OHM
O_H_M{at}BTInternet{dot}com
Sorry, I meant None.
I think that the way I dealt with this was to bind it normally to a dataset
with all the normal DataAdapter stuff, but obviously when your NONE
disapears. I got around this I think by inserting the NONE at the top after
the dataset was updated.
Is that a littler clearer now ?
CJ Taylor wrote: And this handled the None issue? Forgive me I just don't see where your going with this.
I understand your hazy, so that could be the reason. =)
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message news:Oz**************@TK2MSFTNGP09.phx.gbl... Hmm, doesent this slow things down a tad ?
As far as I remember, I think I managed to get around this by checking for a updat event on the datatable or some such event and then inserting the <Select Value> in the front of the ComboBox each time.
Mind you, its a bit hazy now.
Regards - OHM CJ Taylor wrote: 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
-- Best Regards - OHM
O_H_M{at}BTInternet{dot}com
--
Best Regards - OHM
O_H_M{at}BTInternet{dot}com
By the way,
no one ever said it was a "great" solution.. hence the name janky a$$
solutions.. =)
Your solution would work too as far as I see it, definnatly more OOP
oriented than mine I suppose, or more .NET friendly for that matter. This
just seemed clear at the time. where were you when I asked this question a
few weeks ago? =)
Peace,
CJ
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:#E*************@tk2msftngp13.phx.gbl... Sorry, I meant None.
I think that the way I dealt with this was to bind it normally to a
dataset with all the normal DataAdapter stuff, but obviously when your NONE disapears. I got around this I think by inserting the NONE at the top
after the dataset was updated.
Is that a littler clearer now ?
CJ Taylor wrote: And this handled the None issue? Forgive me I just don't see where your going with this.
I understand your hazy, so that could be the reason. =)
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message news:Oz**************@TK2MSFTNGP09.phx.gbl... Hmm, doesent this slow things down a tad ?
As far as I remember, I think I managed to get around this by checking for a updat event on the datatable or some such event and then inserting the <Select Value> in the front of the ComboBox each time.
Mind you, its a bit hazy now.
Regards - OHM CJ Taylor wrote: 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
-- Best Regards - OHM
O_H_M{at}BTInternet{dot}com
-- Best Regards - OHM
O_H_M{at}BTInternet{dot}com
CJ,
Why Not??
I would think if you called DataRow.AcceptChanges as CJ suggested on your
"none" row, or used DataRow.Remove before you called Update, the DataAdapter
will be non the wiser. I would expect AcceptChanges to be the "cleaner"
method, while Remove would be the safer method. ;-)
My concern with this technique is "key" conflicts.
Another heavier option would be a DataView wrapper that dynamically added
the row being reported to the listbox, however the DataTable itself would
not contain the actual item. Which would be more code, however it would
avoid the "key" conflicts. A wrapper could keep the "none" row at the top of
the list, even when changing the sort order...
Hope this helps
Jay
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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
Sorry CJ, I wasn't dumping on your idea's. Its just that I was trying to
help someone here several weeks ago on the same subject and that's the
solution I came up with.
Regards - OHM
CJ Taylor wrote: By the way,
no one ever said it was a "great" solution.. hence the name janky a$$ solutions.. =)
Your solution would work too as far as I see it, definnatly more OOP oriented than mine I suppose, or more .NET friendly for that matter. This just seemed clear at the time. where were you when I asked this question a few weeks ago? =)
Peace, CJ "One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message news:#E*************@tk2msftngp13.phx.gbl... Sorry, I meant None.
I think that the way I dealt with this was to bind it normally to a dataset with all the normal DataAdapter stuff, but obviously when your NONE disapears. I got around this I think by inserting the NONE at the top after the dataset was updated.
Is that a littler clearer now ?
CJ Taylor wrote: And this handled the None issue? Forgive me I just don't see where your going with this.
I understand your hazy, so that could be the reason. =)
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message news:Oz**************@TK2MSFTNGP09.phx.gbl... Hmm, doesent this slow things down a tad ?
As far as I remember, I think I managed to get around this by checking for a updat event on the datatable or some such event and then inserting the <Select Value> in the front of the ComboBox each time.
Mind you, its a bit hazy now.
Regards - OHM CJ Taylor wrote: > 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
-- Best Regards - OHM
O_H_M{at}BTInternet{dot}com
-- Best Regards - OHM
O_H_M{at}BTInternet{dot}com
--
Best Regards - OHM
O_H_M{at}BTInternet{dot}com
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eJ**************@TK2MSFTNGP09.phx.gbl... CJ, Why Not??
I would think if you called DataRow.AcceptChanges as CJ suggested on your "none" row, or used DataRow.Remove before you called Update, the
DataAdapter will be non the wiser. I would expect AcceptChanges to be the "cleaner" method, while Remove would be the safer method. ;-)
My concern with this technique is "key" conflicts.
Another heavier option would be a DataView wrapper that dynamically added the row being reported to the listbox, however the DataTable itself would not contain the actual item. Which would be more code, however it would avoid the "key" conflicts. A wrapper could keep the "none" row at the top
of the list, even when changing the sort order...
Wait. How can you add a row to a dataview and not a datatable? Isn't after
all a dataview just some fancy footwork around DataTable.Select() method?
And provide some quick sort capabilities to it as well? So I don't see how
that would work, let me know what I'm missing.
Second of all, with the key conflicts, thats why I suggested the secondary
non-bound table with only 2 fields. Yeah its more code in some cases but
you have more control over your combos. This way, key constraints are not
an issue as they are with strongly typed datasets. You could easily create
a simple method (static if you wished to take in an IList/IListSource
object, a Display Variable and a Value Variable as parameters and easily
create your datatable off that.
I like your idea about keeping none at the top, I just don't now how you
would accomplish this dataview wrapper without being incredibly heavy...
-CJ
Hope this helps Jay
"CJ Taylor" <no****@blowgoats.com> wrote in message news:10*************@corp.supernews.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
Fair enough, I'm not mad at ya. =) I know people have been trying to solve
this thing, I just thought I would throw my hat into the ring.
Obviously, if there is debate here over how to do it, there isn't a "clear"
answer out there. so who is to say who is right or wrong. I, like you are
trying to give a solution to doing it, hopefully, someone will find a better
way. =)
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl... Sorry CJ, I wasn't dumping on your idea's. Its just that I was trying to help someone here several weeks ago on the same subject and that's the solution I came up with.
Regards - OHM
CJ Taylor wrote: By the way,
no one ever said it was a "great" solution.. hence the name janky a$$ solutions.. =)
Your solution would work too as far as I see it, definnatly more OOP oriented than mine I suppose, or more .NET friendly for that matter. This just seemed clear at the time. where were you when I asked this question a few weeks ago? =)
Peace, CJ "One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message news:#E*************@tk2msftngp13.phx.gbl... Sorry, I meant None.
I think that the way I dealt with this was to bind it normally to a dataset with all the normal DataAdapter stuff, but obviously when your NONE disapears. I got around this I think by inserting the NONE at the top after the dataset was updated.
Is that a littler clearer now ?
CJ Taylor wrote: And this handled the None issue? Forgive me I just don't see where your going with this.
I understand your hazy, so that could be the reason. =)
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message news:Oz**************@TK2MSFTNGP09.phx.gbl... > Hmm, doesent this slow things down a tad ? > > As far as I remember, I think I managed to get around this by > checking for a updat event on the datatable or some such event and > then inserting the <Select Value> in the front of the ComboBox each > time. > > Mind you, its a bit hazy now. > > Regards - OHM > > > > > > > CJ Taylor wrote: >> 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 > > -- > Best Regards - OHM > > O_H_M{at}BTInternet{dot}com
-- Best Regards - OHM
O_H_M{at}BTInternet{dot}com
-- Best Regards - OHM
O_H_M{at}BTInternet{dot}com
CJ, Wait. How can you add a row to a dataview and not a datatable? Isn't
after
:-)
I like your idea about keeping none at the top, I just don't now how you would accomplish this dataview wrapper without being incredibly heavy...
Notice that I stated HEAVY and WRAPPER!
I was suggesting using the Proxy Pattern to create a DataView *like* object
that always returned "<none>" for the very first element, otherwise it
returned the actual value of a contained DataView. Any changes to the
contained DataView would be reflected in the DataView *like* object...
A start of such a class might be:
Public Class MyDataView
Implements IBindingList
Implements ISupportInitialize
Implements ITypedList
Private Readonly m_view As DataView
Public Sub New(Byval view As DataView)
m_view = view
End Sub
' Helper property
Protected Readonly Property List() As IList
Get
Return DirectCast(m_view, IList)
End Get
End Property
Public Readonly Count() As Integer Implements ICollection.Count
Get
Return List.Count + 1
End Get
End Property
Default Public Readonly Property Item(ByVal index As Integer) As
DataRowView
Get
Return DirectCast(IList_Item(index) , DataRowView)
End Get
End Property
Private Property IList_Item(ByVal index As Integer) As Object
Implements System.Collections.IList.Item
Get
If index = 0 Then
Return "<none>"
Else
Return List.Item(index - 1)
End If
End Get
Set(ByVal value As Object)
List.Item(index - 1) = value
End Set
End Property
...
End Class
Of course you need to do more work then I show as the DataView returns
DataRowView objects and my IList_Item is attempting to return a string...
Hint DataRowView is not publicly createable I would consider returning
IEditableObject or ICustomTypeDescriptor in the proxy class... then had a
"nop" IEditableObject implementation for None.
I would probably hide most of the implemented methods and expose ones
similar to how the DataView itself does it, as I show with the Item
property.
Of course this DataView *like* class may be more pain then gain, but I
suspect anyone implementing it would have a greater understanding of how
Databinding works ;-)
Second of all, with the key conflicts, thats why I suggested the secondary
Missed that part :-(
Hope this helps
Jay
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com... "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:eJ**************@TK2MSFTNGP09.phx.gbl... CJ, Why Not??
I would think if you called DataRow.AcceptChanges as CJ suggested on
your "none" row, or used DataRow.Remove before you called Update, the DataAdapter will be non the wiser. I would expect AcceptChanges to be the "cleaner" method, while Remove would be the safer method. ;-)
My concern with this technique is "key" conflicts.
Another heavier option would be a DataView wrapper that dynamically
added the row being reported to the listbox, however the DataTable itself
would not contain the actual item. Which would be more code, however it would avoid the "key" conflicts. A wrapper could keep the "none" row at the
top of the list, even when changing the sort order...
Wait. How can you add a row to a dataview and not a datatable? Isn't
after all a dataview just some fancy footwork around DataTable.Select() method? And provide some quick sort capabilities to it as well? So I don't see
how that would work, let me know what I'm missing.
Second of all, with the key conflicts, thats why I suggested the secondary non-bound table with only 2 fields. Yeah its more code in some cases but you have more control over your combos. This way, key constraints are not an issue as they are with strongly typed datasets. You could easily
create a simple method (static if you wished to take in an IList/IListSource object, a Display Variable and a Value Variable as parameters and easily create your datatable off that.
I like your idea about keeping none at the top, I just don't now how you would accomplish this dataview wrapper without being incredibly heavy...
-CJ
Hope this helps Jay
<<snip>>
HI CJ and Jay B.
This was a problem in the ADONET newsgroup. I changed the sample some
minutes ago totaly I did use the northwind database and a dataset and now
it is a datable.
And Jay B is involved so I have to do it right :-) after my acceptchanges
This is the start of the text of a combobox
A ComboBox displays an editing field combined with a ListBox, allowing the
user to select from the list or to enter new text.
I got it as this far, but maybe you can tell what is wrong.
Not the easy answers they are given already.
It is totaly testable, needs only a textbox and a combobox on a form.
Cor
\\\
Private dv As New DataView
Dim bool As Boolean
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("A")
For i As Integer = 0 To 50
dt.Rows.Add(dt.NewRow)
dt.Rows(i)(0) = i.ToString
Next
Me.ComboBox1.BeginUpdate()
dv = New DataView(dt)
'-------------------------------------------------------------
'DOES NOT WORK
'Me.ComboBox1.DataBindings.Add(New Binding("Text", dv, "A"))
'THIS WORKS FINE
Me.TextBox1.DataBindings.Add(New Binding("Text", dv, "A"))
'---------------------------------------------------------------
Me.ComboBox1.DataSource = dv
Me.ComboBox1.DisplayMember = "A"
Me.ComboBox1.ValueMember = "A"
Me.ComboBox1.EndUpdate()
bool = True
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If bool Then
DirectCast(BindingContext(dv), CurrencyManager).EndCurrentEdit()
End If
End Sub
///
Hey Cor,
"Cor" <no*@non.com> wrote in message
news:e1*************@TK2MSFTNGP11.phx.gbl... HI CJ and Jay B.
This was a problem in the ADONET newsgroup. I changed the sample some minutes ago totaly I did use the northwind database and a dataset and now it is a datable.
And Jay B is involved so I have to do it right :-) after my acceptchanges
This is the start of the text of a combobox
A ComboBox displays an editing field combined with a ListBox, allowing the user to select from the list or to enter new text.
I got it as this far, but maybe you can tell what is wrong. Not the easy answers they are given already.
It is totaly testable, needs only a textbox and a combobox on a form.
Cor
\\\ Private dv As New DataView Dim bool As Boolean Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim dt As New DataTable dt.Columns.Add("A") For i As Integer = 0 To 50 dt.Rows.Add(dt.NewRow) dt.Rows(i)(0) = i.ToString Next Me.ComboBox1.BeginUpdate() dv = New DataView(dt) '------------------------------------------------------------- 'DOES NOT WORK 'Me.ComboBox1.DataBindings.Add(New Binding("Text", dv, "A"))
I ran into the same problem this morning (while I sheepishly retreated to my
"drawing board". I did get it to work if I assigned the databinding AFTER I
set the datasource/datamember and the display and value members.
Why, I'm not really sure, but it worked. i don't like that... Try it out
and tell me if you get the same result.
'THIS WORKS FINE Me.TextBox1.DataBindings.Add(New Binding("Text", dv, "A")) '--------------------------------------------------------------- Me.ComboBox1.DataSource = dv Me.ComboBox1.DisplayMember = "A" Me.ComboBox1.ValueMember = "A" Me.ComboBox1.EndUpdate() bool = True End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If bool Then DirectCast(BindingContext(dv),
CurrencyManager).EndCurrentEdit() End If End Sub ///
Hi CJ,
This gives another behaviour (I even forgot it), than with me it goes
copying the previous selection on the place of the changed selection. (Or
something so watch what you are doing)
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Peter |
last post by:
Company thought DB2 will be better than Oracle.
The bottom line is when you do select, the system crash.
I think it may take 4-5 years for DB2 to reach Oracle standard.
Peter
|
by: John Bentley |
last post by:
John Bentley writes at this level:
If we think about our savings accounts then division never comes in (as far as
I can see). We deposit and withdraw exact amounts most of the time. Occasionaly...
|
by: JC |
last post by:
I have several applications that use forms authentication and they are
currently setup to use a single login page. Everything works fine under v1.0
of the framework and everything works fine if I...
|
by: Scott Meddows |
last post by:
We are throwing around the idea of not having a company standard language at my company (Which I'm not too thrilled about). I was
wondering of anyone knew of any articles that they could post to me...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| | |