|
Depends on where the "100+" fields are coming from. Trying to spec a solution to an ill-defined problem.
(I'm currently using Excel to create "data tables" which are then exported as CSV files for use as embedded resources in another app).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi,
I'm using DevExpress Spreadsheet. I divide a number by another number and convert the result to string and then I put it in a cell in spreadsheet. The problem is that the output is an integer, not a double value. How can I fix it?
|
|
|
|
|
Try:
int x = 95;
int y = 3;
string str = ((double) (x / y)).ToString("F2"); Or
int x = 95;
int y = 3;
string str = ((double) x / (double) y).ToString("F2"); Depending on the result you wanted.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I did test it:
MessageBox.Show(((double)(31 / 2)).ToString("F2"));
But the result shows 15.00
How can I solve it?
|
|
|
|
|
Use the other one?
When you write a numeric constant with no fractional component: 31 say, or 2 you are defining an integer constant. Which means that any operations you do with them use integer math: integer divided by integer gives the same type: integer - and any fractional part is discarded.
So 31 / 2 is 15 and casting the result to a double gives the double equivalent or the integer: 15.0
If you want floating point operations, you need at least one floating point operand!
Hence my giving you two versions: one uses integer math, the other floating point.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks.
|
|
|
|
|
And it's taken you a week to test it?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Why not put the double value in the cell rather than converting it to a string?
|
|
|
|
|
The result is integer even when I don't convert it to string value.
|
|
|
|
|
Well without seeing your code it is impossible to guess the answer.
|
|
|
|
|
I have a notification icon running on the taskbar and it would only show its context menu when I right-clicked it.
I wanted to make it show the context menu when clicking the left mouse button, also.
So I attached a handler to the MouseClick event with the following code:
_NotifyIcon.ContextMenuStrip.Show(Control.MousePosition, ToolStripDropDownDirection.AboveRight); This shows the menu properly, but there is one problem.
The menu doesn't go away if I click on another window without choosing an item from the menu. Right now, the only way to make the left-click-shown menu go away is to click a menu item or right-click the notification icon.
The menu that appears when right clicking the icon goes away properly if you click another window on the desktop.
Does anyone know how to make the menu go away if the user clicks another window?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Richard,
is this WinForms? That behavior is unknown to me.
I have menus on NotifyIcons in WinForms, they show automatically with either left or right click, simply by attaching an event handler to the Click event, like so:
notifyIcon.Click += new EventHandler(notifyIcon_Click);
notifyIcon.Visible = true;
...
void notifyIcon_Click(object sender, EventArgs e) {
populateContextMenu();
MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu",
BindingFlags.Instance | BindingFlags.NonPublic);
mi.Invoke(notifyIcon, null);
}
and that is no surprise, the Click event works for both mouse buttons; if you want to get different behavior, you would have to check MouseEventArgs.Button inside the Click handler.
edited, essential code in click handler was missing
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
modified 23-Jul-21 10:02am.
|
|
|
|
|
Thanks Luc, I'll give that a try.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
It works! Thanks!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
You're welcome.
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
|
|
|
|
|
DataGirdView show black screen on some computers.
I don't know how to solve.
DataGirdView setting
this.dGVMemberMain_MemberList.AllowUserToAddRows = false;
this.dGVMemberMain_MemberList.AllowUserToDeleteRows = false;
this.dGVMemberMain_MemberList.AllowUserToResizeColumns = false;
this.dGVMemberMain_MemberList.AllowUserToResizeRows = false;
this.dGVMemberMain_MemberList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dGVMemberMain_MemberList.BackgroundColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("굴림체", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
dataGridViewCellStyle1.ForeColor = System.Drawing.Color.DarkBlue;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dGVMemberMain_MemberList.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
this.dGVMemberMain_MemberList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle2.Font = new System.Drawing.Font("굴림체", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.dGVMemberMain_MemberList.DefaultCellStyle = dataGridViewCellStyle2;
this.dGVMemberMain_MemberList.GridColor = System.Drawing.SystemColors.ControlLight;
this.dGVMemberMain_MemberList.Location = new System.Drawing.Point(7, 70);
this.dGVMemberMain_MemberList.Name = "dGVMemberMain_MemberList";
this.dGVMemberMain_MemberList.RowHeadersVisible = false;
this.dGVMemberMain_MemberList.RowTemplate.Height = 23;
this.dGVMemberMain_MemberList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dGVMemberMain_MemberList.Size = new System.Drawing.Size(758, 222);
this.dGVMemberMain_MemberList.TabIndex = 14;
|
|
|
|
|
To be honest, we really can't help you - you need to start by looking at the computers where it fails, and the computers where it doesn't, and try to establish some connection or difference which separates them into the two groups.
We can't do that: we can't run your code here and see your problem, and we can't access teh computers where it works or doesn't!
Sorry, but ... there is nothing we can do!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thank you.
Start some computer Windows 10 installation.
now~~
|
|
|
|
|
You're welcome!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Maybe the "black screens" are the ones with no data; and they're "black" because of your (background) color choices.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
|
Hello. I want to open a connection to a local server, the NORTHWND database. When I open the connection it does not print the desired data I requested below.I do not get anything. Just black window on console when I run code. Here is the code
<pre lang="C#">using System;
using System.Linq;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.IdentityModel.Protocols;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
try
{
using (sqlConnection)
{
sqlConnection.Open();
Console. WriteLine("State of connection {0}", sqlConnection.State.ToString());
Console.WriteLine("Name of Base {0}", sqlConnection.Database);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
sqlConnection.Close();
}
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="Northwind" connectionString="Data Source=.;Initial Catalog=NORTHWND;Integrated Security=SSPI"/>
</connectionStrings>
</configuration>
|
|
|
|
|
There are just too many possible problems here for us to be able to tell - it needs your code running on your system, with your data - and we do not have access to that.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Probably not the cause of your problem but ...
You are abusing the 'using' keyword. It is meant to be used to create and dispose of objects, but you have already created it and then you manually close it at the end.
Even so, you should get one of your WriteLine's to display.
As @OriginalGriff has already said ... use the debugger.
|
|
|
|
|
I would like to place a gauge on my form. I did an online search and there are quite a few programs but these programs are expensive for a newbie/hobbyist. Can anyone suggest an inexpensive way to accomplish this problem?
application type: Controlling servo or stepper motor.
the gauge you're trying to make: Analog to indicate the position in degrees to name one type.
the code you've used: To create a gauge. None.
the problem you're having: I don't know how to create a gauge.
Thank you for any help,
Ken
modified 18-Jul-21 13:19pm.
|
|
|
|