|
And last of all you can reconstruct your datasource to match the column order you require and bind that you the DGV.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Hello All,
I am tasked with performing researching of moving on-premise .net websites(4 different websites) to cloud.
I have to perform comparison of Azure, AWS, Google Cloud Service. Is there any other solutions?
What would be the best way to perform this research and document side-by-side pros and cons?
Thank you!!
|
|
|
|
|
I think the best way would be to learn as much as you can about each cloud provider and compare their offerings.
Don't forget the IBM cloud. That leverages their famous Watson technology.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi!
I have a DataGridView in a Windows Form application where I want to localize the columns in the DataGridView. I use the DataGridView 's DataSource property to populate the DataGridView from a list. Therefore the columns in the DataGridView are genereated automatically after the properies in the list.
Here is the code to populate the DataGridView.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var p1 = new Person() { Name = "Foo", Age = 1337 };
var p2 = new Person() { Name = "Bar", Age = 42 };
var people = new List<Person>() { p1, p2 };
dataGridView1.DataSource = people;
}
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
} The generated columns in the DataGridView are Name and Age , the same as the properties in the Person class.
I have set the Form's Localizable property to True .
With a Label in the Form, I have verified that I can change the Label's Text property to different values based on the CurrentCulture / CurrentUICulture I set. I switch between different cultures in the Program.cs file:
static class Program
{
[STAThread]
static void Main()
{
var eng = "en";
var swe = "sv-SE";
var culture = eng;
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
} My project have generated Form1.resx and Form1.sv.resx files to handle both English and Swedish. In these files I can find the label's text for the English and Swedish languages accordingly.
I just don't know how to set the DataGridView's column to different languages. Since the columns are not manually created by me I don't have the appropriate values in the Form1.resx and Form1.sv.resx to set the columns based on the selected language.
Is there any solution to this?
|
|
|
|
|
Because of the way DGV columns are created, you are going to have to iterate over them to localize them: [^].
Look at this excerpt from Hans Passant's code in the link:
foreach (DataGridViewColumn col in dgv.Columns) {
resources.ApplyResources(col, col.Name);
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Hello,
I have a simple Arduino robot that communicates through a Bluetooth device (HC-05).
First I made an application in Microsoft Visual C# 2008 that continuously could receive data from the HC-05.
In this Csharp application I just have to place the serialPort1 object and use the serialPort1_DataReceived event. This is working great ! Each time my robot sends three bytes of data, my application successfully receives this.
Now I have Microsoft Visual Studio Professional 2019 and it seems that I could not use the serialPort1 any more...
So I looked on internet and I found a solution with the package "In The Hand Bluetooth from 32feet.NET".
I installed and used successfully this package. Now I can sent and receive data with the HC-05 device.
However, I can only let this work on the event of a button...
So the big problem that I have now is that I cannot receive continuously data like my old application.
I was trying to make a thread that continuously reads data but it doesn't work:
<pre>
FormManager.BluetoothStream = FormManager.bluetoothClient.GetStream();
try
{
Array.Clear(bufferBluetooth, 0, bufferBluetooth.Length);
do
{
FormManager.BluetoothStream.Read(bufferBluetooth, 0, bufferBluetooth.Length);
}
while (FormManager.BluetoothStream.DataAvailable);
System.Diagnostics.Debug.WriteLine("--> bytes received " + bufferBluetooth[0] + " " + bufferBluetooth[1] + " " + bufferBluetooth[2]);
}
catch
{
System.Diagnostics.Debug.WriteLine("Receiving Error");
}
|
|
|
|
|
It looks like you are expecting a continuous stream of data coming in. As soon as your application has caught up (or if there is no data initially to read), your do...while loop will exit and nothing will then read further incoming data. It is improbable that your bluetooth device will be sending data continuously fast enough to satisfy your loop. In comparison, your previous version, being event driven, could wait for further data. You need to see if there is any event driven equivalents in the new package or if there is any way of suspending until new data arrives.
Note: I know nothing about Bluetooth or about the old or new packages that you have been using, so my thoughts could be wrong!
|
|
|
|
|
Hello,
I got it working by using the read and try command.
And this in a loop that I can put later into a thread:
byte[] buffer = new byte[3];
Stream mStream = FormManager.bluetoothClient.GetStream();
while (FormManager.bluetoothClient.Connected)
{
try
{
mStream.Read(buffer, 0, buffer.Length);
System.Diagnostics.Debug.WriteLine("read status "+buffer[0] + " " + buffer[1] + " " + buffer[2] + " --> Status " + FinalResultBT);
}
catch
{
System.Diagnostics.Debug.WriteLine("read status fail ");
}
}
|
|
|
|
|
I'm using a typical 'n-tier' design. In most cases the BL just passes through called to and from the UI and DAL. But I do have some business rules that I'd like to check in the BL. I want to put the code there, versus in the UI because I have a WPF app and a Mobile app both calling the Web API.
So, the question is, how would you handle a rule violation in the BL? Would you throw an exception? Or return a string or other value?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Richard Deeming wrote: Return an error status code
Thanks. I was leaning in that direction but wanted to get opinions.
I also posted a question in Arch & Design. I would welcome your thouhts on that.
K
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
HI im new to C#
im creating an test app to connect to a local Database, i have created a form which connects to my DB and server, once connected this opens a new form. So far so good. what i need to know now is how do i use the connection in the new form?
thanks
|
|
|
|
|
Exactly how depends on the "relationship" between the two forms.
Have a look at these, one of them will fit your circumstances.
The form that creates an instance of another:
MyForm mf = new MyForm();
mf.Show(); Is the "parent", the other form is the "child".
(This doesn't imply any formal MDI relationship)
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
But ... you shouldn't create a SqlConnection and "pass it around" your app - that's a bad idea as some operations such as a DataReader that fails to be closed and disposed properly can "block" the connection object from doing anything else. Instead, create a connection string and pass that around (or create it as a public static property and just use it everywhere). Then create your Connection within a using block each time you need one.
"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 for your reply i will take look at the parent child
this is my first app, advancing from hello world . passing the connection string between forms is what i am trying to do. I am a complete Novice.
thanks
|
|
|
|
|
You don't have to "pass" anything. The connection string can be made available to any methods that want it by exposing it as a getter-only property in a static class.
Seriously, if you're moving up from Hello World to this, you may have taken your steps a bit too long.
|
|
|
|
|
If you're creating a connection to the database in your login form to share amongst all other forms, DON'T.
All database operations should be Create Connection as late as possible, do your work, and close connection as early as possible.
DO NOT HOLD A DATABASE CONNECTION OPEN FOR THE LIFE OF YOUR APP.
Also, is a login form really the correct place to open a database connection used by the entire app? Does it have anything to do with the operation of authenticating users in your app?
No, it does not. That is a violation of "separation of concerns". The authentication form should be limited to just that, getting the user credentials and authenticating them. That's it. Nothing else.
The database work should be handled different classes specific to their tasks.
|
|
|
|
|
I Parent, Owner
let me clear something up here:
1) when you declare and instantiate a Form within another Form: they do not have a Parent-Child relationship. It is simply the case at run-time that the instance of the Form that creates the second Form has a valid reference to the instance of the second Form.
2) imho, it's regrettable that it's legal to set a Form to be the Parent of another Form: that leads to a form-within-a-form which is a code smell: you can use the light-weight ContainerControls, like Panel, instead.
3) you can set a Form to be the Owner of another Form ... imho, that is a kind of Parent-Child relationship ... but, all it does is make sure the owned Form appears in front of the owning Form at run-time.
.
II Security in getting and passing data from one Form to another
0) the goal here is to implement security by encapsulation/separation of concerns: all objects/delegates created in the main form Load event do not persist outside that method. the log in form has no "world knowledge" of the main form. there is only one point of access to the log in form in the main form: being able to set the Action delegate 'SendResult in the log in form.
just for the sake of over-kill, we inject the executable code using the lambda format. for a good summary of using Action and Func rather than delegates: [^]
1) code example in a Main Form named Form1's Load EventHandler:
private void Form1_Load(object sender, EventArgs e)
{
LogInForm loginfrm = new LogInForm();
string username, password;
loginfrm.SendResult = (uname, pword) =>
{
username = uname;
password = pword;
};
DialogResult loginResult = loginfrm.ShowDialog();
if (loginResult == DialogResult.OK)
{
}
else if (loginResult == DialogResult.Cancel)
{
}
else if (loginResult == DialogResult.Abort)
{
}
} 2) code in the LogInForm
using System;
using System.Windows.Forms;
namespace YourNameSpace
{
public partial class LogInForm : Form
{
public LogInForm()
{
InitializeComponent();
}
public Action<string, string> SendResult;
private void btnLoginAttempt_Click(object sender, EventArgs e)
{
if (textBox1.Text != "" && textBox2.Text != "")
{
if (SendResult != null)
{
SendResult(textBox1.Text, textBox2.Text);
this.DialogResult = DialogResult.OK;
}
else
{
this.DialogResult = DialogResult.Abort;
}
}
else
{
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
} An alternative use of the Delegate/Func: unless the user's log-in data is validated, the log-in form stays open. In real=world code, ypu'd want to keep track of the attempts, and abort the log in after so many attempts;
// in the Main Form
private void Form1_Load(object sender, EventArgs e)
{
LogInForm loginfrm = new LogInForm();
string username, password;
loginfrm.SendResult = SendResult;
DialogResult loginResult = loginfrm.ShowDialog();
if (loginResult == DialogResult.OK)
{
}
else if (loginResult == DialogResult.Cancel)
{
}
else if (loginResult == DialogResult.Abort)
{
}
}
private bool SendResult(string uname, string pword)
{
username = uname;
password - pword;
return false;
} the revised log-in form:
using System;
using System.Windows.Forms;
namespace YourNameSpaace
{
public partial class LogInForm : Form
{
public LogInForm()
{
InitializeComponent();
}
public Func<string, string, bool> SendResult;
private void btnLoginAttempt_Click(object sender, EventArgs e)
{
if (textBox1.Text != "" && textBox2.Text != "")
{
if (SendResult != null)
{
if (SendResult(textBox1.Text, textBox2.Text))
{
this.DialogResult = DialogResult.OK;
}
}
else
{
this.DialogResult = DialogResult.Abort;
}
}
else
{
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 3-Nov-20 21:08pm.
|
|
|
|
|
Thanks, i will have a good read and give that a bash 
|
|
|
|
|
I will add an alternate example where the 'SendResult Func/Delegate is triggered within the log-in form, and a more standard EventHandler declaration is used in the main form: this may be clearer.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Im very new to this and i usually search the web for the answer but i got stucked and i need help from community.
I have two datagridview on different tables and i wanna show them on a same crystal report.
Iv done it with one of em using XML Schema but what to do with other datagridview.
TY in advance
|
|
|
|
|
2 reports right after one another is the same as 1 report. Or combine the 2 grids if you want "2 up" (and can't figure out how to put 2 grid controls on one row).
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,
Can anybody give me any guidance on how to create an if else statement on a background colour of a label.
For example, if the background colour of a label is white then do this else do this.
|
|
|
|
|
if (backcolor == "white")
{
}
else
{
}
Although you may wish to clarify your question with some more details of exactly what your code is trying to do.
|
|
|
|
|
Hello
thanks for such a quick reply and help, I have a mouse leave event on label 28. where once you leave the label it changes white.
then when you finish the maze at finish_point i want it to check if the label28 background colour is white. if it is then do the below close between the {} else bring up a message box stating you haven't found the treasure/ loot.
private void Finish_Point(object sender, EventArgs e)
{
this.Close();
th = new Thread(opennewform);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
|
|
|
|
|
Don't rely on colours - instead create a class level bool that tells you "the user left the label" instead. It's a lot more readable (and thus maintainable) and less prone to error later when you change things around.
"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!
|
|
|
|