How can I format date in databound combobox in windows app?

  • Thread starter Thread starter George P.
  • Start date Start date
G

George P.

Hi,
I have a combobox bound to a smalldatetime column in a table.
The ComboBox displays all available dates.
However it displays them in long format and I want to display them in short
format.
Is this possible?
 
George,

Here is how you do it -
PopulateDataSet();
Binding bnd = new Binding("Text", ds.Tables[0], "date");
bnd.FormatString = "dd-MM-yy";
bnd.FormattingEnabled = true;
comboBox1.DataBindings.Add(bnd);

Now, I don't have Visual Studio 2003 installed on my machine :-/ (or any of
my machines), and I suspect that FormatString was a new fangled thing
introduced in 2.0. So this just might be a 2.0 only thing. Atleast off the
top of my head, I don't remmeber seeing a FormatString property on Binding
in framework 1.1, but I could be wrong.

Anyway, thats how you do it. And this is yet another reason I am so anxious
to have 2.0 released !! HEHE :-)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
http://blogs.apress.com/authors.php?author=Sahil Malik
 
BTW, even in 1.1, you could add a data column, set expression and bind with
that instead.

- Sahil Malik
You can reach me thru my blog -
http://www.dotnetjunkies.com/weblog/sahilmalik

Sahil Malik said:
George,

Here is how you do it -
PopulateDataSet();
Binding bnd = new Binding("Text", ds.Tables[0], "date");
bnd.FormatString = "dd-MM-yy";
bnd.FormattingEnabled = true;
comboBox1.DataBindings.Add(bnd);

Now, I don't have Visual Studio 2003 installed on my machine :-/ (or any
of
my machines), and I suspect that FormatString was a new fangled thing
introduced in 2.0. So this just might be a 2.0 only thing. Atleast off the
top of my head, I don't remmeber seeing a FormatString property on Binding
in framework 1.1, but I could be wrong.

Anyway, thats how you do it. And this is yet another reason I am so
anxious
to have 2.0 released !! HEHE :-)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
http://blogs.apress.com/authors.php?author=Sahil Malik







George P. said:
Hi,
I have a combobox bound to a smalldatetime column in a table.
The ComboBox displays all available dates.
However it displays them in long format and I want to display them in short
format.
Is this possible?
 
Hi there,
VS.net 2003 doesn't have a FormatString property for binding,
but it has Format and Parse events that you can use. However it's not the
bound property that I want to format but the display member.
My combobox displays all possible dates from one column
and the selected value(which is taken from another column) is bound to
another table.
I want to perform formatting on the displaymember
not on the selected value which is databound.
cheers,
george

Sahil Malik said:
George,

Here is how you do it -
PopulateDataSet();
Binding bnd = new Binding("Text", ds.Tables[0], "date");
bnd.FormatString = "dd-MM-yy";
bnd.FormattingEnabled = true;
comboBox1.DataBindings.Add(bnd);

Now, I don't have Visual Studio 2003 installed on my machine :-/ (or any of
my machines), and I suspect that FormatString was a new fangled thing
introduced in 2.0. So this just might be a 2.0 only thing. Atleast off the
top of my head, I don't remmeber seeing a FormatString property on Binding
in framework 1.1, but I could be wrong.

Anyway, thats how you do it. And this is yet another reason I am so anxious
to have 2.0 released !! HEHE :-)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
http://blogs.apress.com/authors.php?author=Sahil Malik







George P. said:
Hi,
I have a combobox bound to a smalldatetime column in a table.
The ComboBox displays all available dates.
However it displays them in long format and I want to display them in short
format.
Is this possible?
 
George,

As in the pasted code - the use "Text" as the first parameter.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik



George P. said:
Hi there,
VS.net 2003 doesn't have a FormatString property for binding,
but it has Format and Parse events that you can use. However it's not the
bound property that I want to format but the display member.
My combobox displays all possible dates from one column
and the selected value(which is taken from another column) is bound to
another table.
I want to perform formatting on the displaymember
not on the selected value which is databound.
cheers,
george

Sahil Malik said:
George,

Here is how you do it -
PopulateDataSet();
Binding bnd = new Binding("Text", ds.Tables[0], "date");
bnd.FormatString = "dd-MM-yy";
bnd.FormattingEnabled = true;
comboBox1.DataBindings.Add(bnd);

Now, I don't have Visual Studio 2003 installed on my machine :-/ (or any of
my machines), and I suspect that FormatString was a new fangled thing
introduced in 2.0. So this just might be a 2.0 only thing. Atleast off the
top of my head, I don't remmeber seeing a FormatString property on Binding
in framework 1.1, but I could be wrong.

Anyway, thats how you do it. And this is yet another reason I am so anxious
to have 2.0 released !! HEHE :-)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
http://blogs.apress.com/authors.php?author=Sahil Malik







George P. said:
Hi,
I have a combobox bound to a smalldatetime column in a table.
The ComboBox displays all available dates.
However it displays them in long format and I want to display them in short
format.
Is this possible?
 
Back
Top