|
Sorry, no idea. You could try one of the Microsoft help forums.
|
|
|
|
|
i have many payment rows in same date and i want to count how many payments i this date and put count result in new 1 row
i'm made it manually by excel but i want make it in c# with SQL Server & Data Grid View
this 2 photos make you understand
https://i.stack.imgur.com/mWj1M.png
https://i.stack.imgur.com/UhOzB.png
|
|
|
|
|
Try:
SELECT MyDateField, COUNT(MyDateField)
FROM MyTable
GROUP BY MyDateField
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I've a nested n-level TreeView that consists of data such as grand father, father, child, and list goes on further. I want to bind Selected TreeView Item to so that I can get the Name and Age of selected person using Linq. Please help me. I'll be very grateful of you.
public class Person
{
public Person()
{
Children = new ObservableCollection<Person>();
}
public string Name { get; set; }
public int Age { get; set; }
public ObservableCollection<Person> Children { get; set; }
}
ObservableCollection<Person> Souce = new ObservableCollection<Person>();
Person P1 =
new Person()
{
Name = "GrandFather",
Age = 90
};
Person P11 = new Person()
{
Name = "Father1",
Age = 60
};
Person P111 = new Person()
{
Name = "Child1",
Age = 30
};
P11.Children.Add(P111);
Person P12 = new Person()
{
Name = "Father2",
Age = 60
};
P1.Children.Add(P11);
P1.Children.Add(P12);
Person P2 =
new Person()
{
Name = "GrandFather2",
Age = 91
};
Person P3 =
new Person()
{
Name = "GrandFather3",
Age = 92
};
Souce.Add(P1);
Souce.Add(P2);
Souce.Add(P3);
trVwPerson.ItemsSource = Souce;
My XAML:
<TreeView Name="trVwPerson" xmlns:obj="clr-namespace:TestWpf">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType = "{x:Type obj:Person}" ItemsSource="{Binding Path=Children}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}"/>
<TextBlock Width="10"/>
<TextBlock Text="{Binding Path=Age}"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
|
|
|
|
|
Shouldn't that just be:
<TreeView SelectedItem="{Binding SelectedPerson, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> Then in your view model you must have a property to connect the binding:
class ViewModel
{
public Person SelectedPerson { get; set; }
} However, you don't seem to have a view model for the entire TreeView.
I think you can set the TreeView's DataContect to an instance of the ViewModel.
For instance:
trVwPerson.DataContext = new ViewModel() But instead I suggest you specify the ViewModel to the MainWindow/UserControl containing the TreeView. For instance: You have your TreeView in your MainWindow or maybe a UserControl to contain the TreeView. For that container specify its DataContext to an instance of the ViewModel.
class MainWindow
{
public MainWindow()
{
this.DataContext = new ViewModel();
}
}
You also need to implement the INotifyPropertyChanged in the ViewModel.
However this is kinda clunky, ugly and tedious. Instead I recommend you use an automatic implementation of INotifyPropertyChanged as a NuGet-package. For instance: PropertyChanged.
I think that should give you some advice how fix your problem.
I have note tested my code, so have in mind if it's now is working right off.
Best regards,
/Steffe
|
|
|
|
|
I have the following code, I put a label in Form_Paint to track the number jump, I see the label jumping continuously but e.Graphics.DrawString(...) only looks once, does anyone know why ?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
progressBar1.Minimum = 0;
progressBar1.Maximum = 100;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
int iNum = 0;
private void btnDrawText_Click(object sender, EventArgs e)
{
progressBar1.Value = 0;
progressBar1.Visible = true;
this.timer1.Interval = 100;
this.timer1.Enabled = true;
}
private void ShadowedTextPaint(PaintEventArgs e, int num)
{
using (Font font1 = new Font("Times New Roman", 250, FontStyle.Bold, GraphicsUnit.Pixel))
{
PointF pointF1 = new PointF(310, 270);
e.Graphics.DrawString(num.ToString(), font1, Brushes.LightGreen, pointF1);
lblNum.Text = num.ToString();
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
ShadowedTextPaint(e, iNum);
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value < 100)
{
Random rd = new Random();
iNum = rd.Next(0, 999);
progressBar1.Value++;
}
else
{
this.timer1.Enabled = false;
progressBar1.Visible = false;
}
}
}
|
|
|
|
|
My first guess would be it's because you're setting the Text property of a Label control in your paint event, which will cause the label to Invalidate and require painting, which may be generating another WM_PAINT message for your form.
Handle the paint event, but only do painting in it, not messing with other controls that have nothing to do with drawing content.
Also, your in Tick event handler, the else clause of the If statement is unnecessary. The Timer control in the ToolBox does not need to be re-enabled on every tick, and the ProgressBar is always going to be visible since you never set it to not be visible.
Your Random really shouldn't be recreated on every tick of the timer. You can just create a single instance as the class level and just keep using that. But, since you're not even using the random numbers you're getting, why even have it in there?
|
|
|
|
|
The Label Control I put in the Form_Paint event is for me to troubleshoot it without affecting or messing up the information in the Form_Paint event or argument, I verified this with the Debug.Print debugger ("..." );
My Random function gets a random number and the Tick event determines the time to stop redrawing, the ideas you give me are incorrect.
What do you think is the use of Form_Paint to draw random numbers continuously over time ?
|
|
|
|
|
The Label control was a bad idea because it changes the behavior of your code. When you set the value of the Text property, the label does not get repainted at that time. It forces the label to Invalidate itself, telling Windows that it needs to repaint. Windows will get around to posting a WM_PAINT message to the applications message queue. When the UI thread finally goes back to idle, the queue will get processed and the paint message makes it way to the label control, telling it that it is now OK to paint itself. That is when the label actually changes on screen.
Moving on, you never use the value of the Random so it's never being painted anywhere.
Form_Paint is a bit much for this. I'd create a Control specifically for the purpose. This makes the code reusable and easily maintained.
The control would have it's own Random, it's own Timer, and a couple of methods to Start and Stop it's behavior.
|
|
|
|
|
I use the label control to debug the program instead of the Debug.Print("..."), I think the label control doesn't affect as you say.
you say: "i never use the value of the Random so it's never being painted anywhere." What do I use to generate random numbers ?
you say: "Form_Paint is a bit much for this. I'd create a Control specifically for the purpose ..." I haven't seen you create a Control specifically posted by you for everyone to see ?
|
|
|
|
|
Member 2458467 wrote: I use the label control to debug the program instead of the Debug.Print("..."), I think the label control doesn't affect as you say.
Actually, it does work as I say, and it WILL lie to you when you have the UI thread tied up doing other things instead of letting it process the message pump so forms and controls can repaint themselves.
Don't believe me? Start a new Windows form project and drop a label and a button on the form. Double click the button to create an event handler and drop the following code into the button handler:
for (int i = 1; i < 20000000; i++)
label1.Text = i.ToString();
Run it and click the button. Notice the label doesn't update? Also, you can't move the form around the screen either. It's doing this because you've got the UI thread tied up doing a long-running operation. It's can't process messages, like WM_PAINT, until that operation completes.
Member 2458467 wrote: you say: "i never use the value of the Random so it's never being painted anywhere." What do I use to generate random numbers ?
You use Random to generate the values, but you're not understanding how Random works. When you create a new instance of Random and do not supply it with a seed value, it will use the current timer value. Do this multiple times in a row quick enough, and each one of the Random instances will return the exact same value!
Create a single class-level instance of Random and you can use it throughout the rest of your class code and not have to worry about consecutive instances returning the same values.
public class Form1 : Form
{
private Random RNG = new Random();
.
.
.
private void SomeMethod()
{
...
int x = RNG.Next(10000);
...
}
}
In your code, you're getting the next random value and putting it in a variable, but then you never use that value in your paint code!
Member 2458467 wrote: you say: "Form_Paint is a bit much for this. I'd create a Control specifically for the purpose ..." I haven't seen you create a Control specifically posted by you for everyone to see ?
Because I've got my own code to write that nobody is going to write for me and I'm not in the business of writing other peoples code for them.
But, yeah, I wrote a tons of controls for specific very specific things. You'd be better served by writing a control to do this instead of baking it into the Form code where it cannot be used on other forms without copying all the code for it.
Putting the code in its own control allows you to easily reuse the functionality in other applications, other forms in the same app, and even multiple instances of the control on the same form, all without duplicating in multiple places.
Actually, for this, I'd probably just forget the custom painting, even though it's easy to do, it's a bit more code and there's stuff you have to worry about when painting. I'd probably just create a new class, inherit from Label, add a timer to it, a few methods to start and stop the timer, a few properties like Interval for the timer, and in the Tick event of the timer, just update the number being displayed and call Invalidate to get the control to repaint itself.
...no custom painting required.
|
|
|
|
|
How to search any query on c#?
|
|
|
|
|
I'm sorry but that is not a question we can answer just like that - we cannot work out from that little what you are trying to do.
We have no idea - other than "it's in C#" - what type of query you are trying to search, where your data is, how it's organised or even stored, what kind of search you are trying to do, what results you expect, what you have tried, where you are stuck, or any idea what help you want from us!
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with, we get no context beyond that at all.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
What!!?
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
He's on second.
Who's on first, I don't know is on third.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: He's on second.
Who's on first, I don't know is on third. That's less confusing than the OP's message.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Your question is simplistic in the extreme and isn't answerable. It's not even a question.
"How" you "search" is dependent on "what" you're searching through, the functionality and options you want the search to support, the data source you're searching, how you want results returned, any metadata considerations, ...
The quality of the answers you get are directly dictated by the quality of the questions you ask.
|
|
|
|
|
Assuming you have some MySQL database with the appropriate table the codes may look like this:
public List<string> GetAnswers(string question) {
List<string> answers=new List<string>();
string connectionString=@"SERVER=localhost;DATABASE=myDatabase;UID=me;PASSWORD=1234;";
try {
using (MySqlConnection dbCon=new MySqlConnection(connectionString)) {
dbCon.Open();
question=question.Split(';')[0];
string query="SELECT answer FROM AnswersToAllQuestions "+
" WHERE question LIKE '%"+question+"%'";
using (MySqlCommand dbCmd=new MySqlCommand(query, dbCon)) {
using (MySqlDataReader reader=dbCmd.ExecuteReader()) {
while (reader.Read()) {
string answer=(string)reader["answer"];
answers.Add(answer);
}
}
}
dbCon.Close();
}
} catch (Exception exc) {
Console.WriteLine(exc.ToString());
}
return answers;
}
For other databases, some minor modifications would be needed.
Reading an article or a book on database access might be a good starter...
modified 22-Oct-19 16:47pm.
|
|
|
|
|
Luc Pattyn wrote:
question=question.Split(';')[0];
string query="SELECT answer FROM AnswersToAllQuestions "+
" WHERE question LIKE '%"+question+"%'"; No no no no no no no!
There are plenty of ways to exploit that code without having to insert a semi-colon into the string.
Given how simple it is to do the right thing in .NET, it amazes me what lengths people will go to to do it wrong.
using (MySqlConnection dbCon=new MySqlConnection(connectionString)) {
dbCon.Open();
const string query = "SELECT answer FROM AnswersToAllQuestions WHERE question LIKE '%' + @question + '%'";
using (MySqlCommand dbCmd = new MySqlCommand(query, dbCon)) {
dbCmd.Parameters.AddWithValue("@question", question);
using (MySqlDataReader reader = dbCmd.ExecuteReader()) {
while (reader.Read()) {
string answer = (string)reader["answer"];
answers.Add(answer);
}
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, you're right in principle.
Unfortunately MySQL does not like that approach.
To make it work, one has to settle for something like:
const string query = "SELECT answer FROM AnswersToAllQuestions WHERE question LIKE @question";
using (MySqlCommand dbCmd = new MySqlCommand(query, dbCon)) {
dbCmd.Parameters.AddWithValue("@question", "%"+question+"%");
|
|
|
|
|
|
Super Lloyd wrote: But now if fails That is like the people who post in QA who write, "but it is not working". Unless you provide some details of exactly what is failing then it's anyone's guess what might be happening.
|
|
|
|
|
By "not working" I mean that when I look for an existing user it was previously returning it and now it returns null.
maybe the sysadmin change some AD setting? I am not sure one can search AD properties in the LDAP query without some AD server customisation. Maybe there is an AD settings for that? I wonder if any one knows ....
|
|
|
|
|
Super Lloyd wrote: maybe the sysadmin change some AD setting? Maybe ...
|
|
|
|
|
Odd thing: I have some ToolStripMenuItems in a ContextMenuStrip: when the Text of the item begins with a '#' character, the text appears bolded.
This is an English language app; I'm using the default Segoe 9pt. font in the ContextMenuStrip; items are set to display text only; and, items are checkable.
Seen that one ?
«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
|
|
|
|
|