473,322 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Changing ComboBox Contents

Hey folks,

I've got a combobox (DropDown List) in a windows form application which is
bound to a DataSet.
It's value is set to a numeric ID. It's visible text is set to a date. I
need to make it so that the first item shows the words "Most Recent" instead
of the date.

I've tried setting the SelectedItem, Text, and SelectedText of the list box
to "Most Recent", when the SelectedIndex changes to 0, but nothing happens.
I also tried changing it in the dataset before (and after) it is bound, by
doing
ds.Tables[0].Rows[0].ItemArray[1] = "Most Recent", but that does nothing
either. It always displays the date instead. I think it may be related to
the fact that the ValueType in the DataSet is a DateTime.

Any idea how to accomplish this?
Nov 16 '05 #1
2 4255
John,

Because the list is data bound, the selected item has to be within the data
itself. And yes, I suspect that the problem with changing the dataset is that
the column in question should be a date.

If you are getting the dataset via a SQL select command, you could use a
query such as:
SELECT 0 AS ID, 'Latest Revision' AS Date
UNION
SELECT id, CONVERT(varchar(30),thedate) FROM mytable

assuming that there are no items in the table with ID = 0.

Chris.

"John Smith" wrote:
Hey folks,

I've got a combobox (DropDown List) in a windows form application which is
bound to a DataSet.
It's value is set to a numeric ID. It's visible text is set to a date. I
need to make it so that the first item shows the words "Most Recent" instead
of the date.

I've tried setting the SelectedItem, Text, and SelectedText of the list box
to "Most Recent", when the SelectedIndex changes to 0, but nothing happens.
I also tried changing it in the dataset before (and after) it is bound, by
doing
ds.Tables[0].Rows[0].ItemArray[1] = "Most Recent", but that does nothing
either. It always displays the date instead. I think it may be related to
the fact that the ValueType in the DataSet is a DateTime.

Any idea how to accomplish this?

Nov 16 '05 #2
Thanks Chris,

I had thought about doing something similar to your suggestion but it would
be a bit tough because the dataset is populated from a system wide search
class I had created.

Instead I did:
System.Windows.Forms.ListViewItem []ls = new
ListViewItem[ds.Tables[0].Rows.Count];

ls[0] = new ListViewItem();

ls[0].Tag = ds.Tables[0].Rows[0].ItemArray[0].ToString();

ls[0].Text = "Current";

for(int i=1; i<ds.Tables[0].Rows.Count; i++)

{

ls[i] = new ListViewItem();

ls[i].Tag = ds1.Tables[0].Rows[i].ItemArray[0].ToString();

ls[i].Text = ds1.Tables[0].Rows[i].ItemArray[1].ToString();

}

this.lstBox.DataSource = ls;

this.lstBox.DisplayMember = "Text";

this.lstBox.ValueMember = "Tag";


"Chris Ballard" <Ch**********@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
John,

Because the list is data bound, the selected item has to be within the data itself. And yes, I suspect that the problem with changing the dataset is that the column in question should be a date.

If you are getting the dataset via a SQL select command, you could use a
query such as:
SELECT 0 AS ID, 'Latest Revision' AS Date
UNION
SELECT id, CONVERT(varchar(30),thedate) FROM mytable

assuming that there are no items in the table with ID = 0.

Chris.

"John Smith" wrote:
Hey folks,

I've got a combobox (DropDown List) in a windows form application which is bound to a DataSet.
It's value is set to a numeric ID. It's visible text is set to a date. I need to make it so that the first item shows the words "Most Recent" instead of the date.

I've tried setting the SelectedItem, Text, and SelectedText of the list box to "Most Recent", when the SelectedIndex changes to 0, but nothing happens. I also tried changing it in the dataset before (and after) it is bound, by doing
ds.Tables[0].Rows[0].ItemArray[1] = "Most Recent", but that does nothing
either. It always displays the date instead. I think it may be related to the fact that the ValueType in the DataSet is a DateTime.

Any idea how to accomplish this?

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Tyce | last post by:
When a button is clicked, a date is inserted or added into a combo box like this : ComboBox.Items.Add(string) or ComboBox.Items.Insert(0,string); Either way, the new string does not show up in the...
9
by: ukjock | last post by:
I am very new to the whole Visual Basic .net scene, and I am trying to get to grips with it... I thought I would try and learn a programming language, and I was advised on vb.net. I have already...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
7
by: Arnold | last post by:
Greetings Gurus, In a mainform's header, I have a combobox named comboStudents. The rowsource for this combobox is: SELECT -999 As StudentID, "<Add New Student>" As FullName, "aaa" As...
0
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
7
oll3i
by: oll3i | last post by:
i want to change the values in two columns one colum is a combobox and the secons column is editable too i want to get the value of that second column and the value of combobox and sent that...
0
by: XenReborn | last post by:
Ok this should be simple. I made a form, added a combobox (for selecting items to edit, not for updating fields), several textboxes, a few checkboxes etc. On formshow it connects to my database,...
0
by: dvanmil | last post by:
I am in the process of creating my own custom Open File Dialog and was wondering about one thing that should be the final key to my puzzle. Hopefully someone might have some more insights into this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.