We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Format of a ComboBox

Thread ID:

Created:

Updated:

Platform:

Replies:

63880 Jul 11,2007 08:10 AM UTC Jul 17,2007 08:47 AM UTC Windows Forms 5
loading
Tags: Tools
Mikael Plouhinec
Asked On July 11, 2007 08:10 AM UTC

Hello,

I have a combobox which contains several decimal values.

I would like to know how can I configure my combobox in order to view my values as currency for example.

Thanks a lot.

Mike

Administrator [Syncfusion]
Replied On July 12, 2007 08:52 AM UTC

Hi Mike,

You can format the combobox value using "String.Format" method. Please refer this code snippets:

private void Form1_Load(object sender, EventArgs e)
{
this.comboBoxAdv1.Items.Add(String.Format("{0}134.5","$"));
this.comboBoxAdv1.Items.Add(String.Format("{0}5434.545", "$"));
this.comboBoxAdv1.Items.Add(String.Format("{0}0.5346", "$"));
}

Please refer the small sample in the below link which illustrates the above:
http://websamples.syncfusion.com/samples/Tools.Windows/F63880/main.htm

Kindly let us know if you need any further assistance.

Best Regards,
Jeba.

Mikael Plouhinec
Replied On July 13, 2007 09:12 AM UTC

Ok.

But I don't use the method Add of Items. I use this :

this.comboBoxTauxTvaInitial.DataSource = Satori.Tarifs.TauxTVA.GetAllTaux();
this.comboBoxTauxTvaInitial.DisplayMember = "Taux";
this.comboBoxTauxTvaInitial.ValueMember = "OID";

Is there a way to format the displayMember as Currency for example?

Thanks a lot.

Mike

>Hi Mike,

You can format the combobox value using "String.Format" method. Please refer this code snippets:

private void Form1_Load(object sender, EventArgs e)
{
this.comboBoxAdv1.Items.Add(String.Format("{0}134.5","$"));
this.comboBoxAdv1.Items.Add(String.Format("{0}5434.545", "$"));
this.comboBoxAdv1.Items.Add(String.Format("{0}0.5346", "$"));
}

Please refer the small sample in the below link which illustrates the above:
http://websamples.syncfusion.com/samples/Tools.Windows/F63880/main.htm

Kindly let us know if you need any further assistance.

Best Regards,
Jeba.

Jeba S [Syncfusion]
Replied On July 16, 2007 12:20 PM UTC

Hi Mike,

You can achieve this using ComboBoxDropDown and GridListControl.

void Grid_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)
{
if (e.RowIndex > 0 && e.ColIndex > 0)
{
e.Style.CellType = "Currency"; ;
e.Style.CellValueType = typeof(double);
}
if (flag == 1)
{
this.comboDropDown1.TextBox.Text = e.Style.FormattedText;
}
}

Please refer the modified sample in the below link which illustrates the above:
http://websamples.syncfusion.com/samples/Tools.Windows/F63880Two/main.htm

Kindly let us know if this helps.

Best Regards,
Jeba.

Mikael Plouhinec
Replied On July 16, 2007 12:48 PM UTC

I don't have any grid.

I just want to know how can I format the display members of my items of my combobox without change the query which give me my DataSource.

Thanks a lot.

Mike

>Hi Mike,

You can achieve this using ComboBoxDropDown and GridListControl.

void Grid_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)
{
if (e.RowIndex > 0 && e.ColIndex > 0)
{
e.Style.CellType = "Currency"; ;
e.Style.CellValueType = typeof(double);
}
if (flag == 1)
{
this.comboDropDown1.TextBox.Text = e.Style.FormattedText;
}
}

Please refer the modified sample in the below link which illustrates the above:
http://websamples.syncfusion.com/samples/Tools.Windows/F63880Two/main.htm

Kindly let us know if this helps.

Best Regards,
Jeba.

Jeba S [Syncfusion]
Replied On July 17, 2007 08:47 AM UTC

Hi Mike,

There is no direct way to format the display members of the items in the combobox.

Best Regards,
Jeba.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;