How to trigger DrillThrough with Report Viewer - c#

I'm using ReportViewer with my WPF application.
I'm trying to trigger a function within my c# code and the button will be on the ReportViewer.
I'm wondering how do I trigger the DrillThrough?
void DemoDrillThroughEventHandler(object sender, DrillthroughEventArgs e)
{
MessageBox.Show("Drillthrough worked");
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
this._reportViewer.Drillthrough += new DrillthroughEventHandler(DemoDrillThroughEventHandler);
this._reportViewer.Reset();
....
this._reportViewer.LocalReport.Refresh();
this._reportViewer.RefreshReport();
}
}

Sometimes there is a method what rises event (OnSomething, to example, in winforms there is Button.PerformClick). Otherwise you can put code from event handler in separate function and call it directly.
Simplest solution to call it
DemoDrillThroughEventHandler(this._reportViewer, new DrillthroughEventArgs());
or even (depends on what is going on inside)
DemoDrillThroughEventHandler(null, null);

Related

Why XAML button can't invoke argumentless function

I have function in create.cs
private void FillGrid()
{
ClearingEntities CE = new ClearingEntities();
var Accountss = CE.Accounts;
DataGrid1.ItemsSource = Accountss.ToList();
}
I invoke this function from other .cs files just writing FillGrid(); without any arguments
but from xaml in button Click="FillGrid" gives error
click auto generated functions have
private void Button_Click(object sender, RoutedEventArgs e)
I don't want insert those object sender, RoutedEventArgs e arguments
if I insert those to my function's arguments then other calling should be changed
to
FillGrid([argument],[argument]);
note: it is not event handling function just fill data stuff
how to call FillGrid() from xaml? without changing create.cs
This is just the way Button Event's work.
Read more about EventHandler here
Why don't you just use this:
<Button Click="FillGridClicked" />
//sender = button, RoutedEventArgs = arguments of that event
private void FillGridClicked(object sender, RoutedEventArgs e)
{
FillGrid();
}
Every ClickEventHandler needs these arguments as it is a custom delegate defined that way. If you really want to emit this you need to extend the button and create a custom click handler for yourself. (see this for example)

html element's attribute in c# web browser by using threading

i am making web browser in windows form by using c# where i can set values of loaded html's input fields automatically by clicking on button. when i simply put code in click event of button its work fine`
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementById("username").SetAttribute("value","admin");
webBrowser1.Document.GetElementById("password").SetAttribute("value","12345");
}`
but when i try to this via threading it gives me error
Specified cast is not valid?
private void button1_Click(object sender, EventArgs e)
{
Thread thread1 = new Thread(new ThreadStart(setvalues));
thread1.Start();
}
void setvalues()
{
webBrowser1.Document.GetElementById("username").SetAttribute("value","admin");
webBrowser1.Document.GetElementById("password").SetAttribute("value","12345");
Thread.Sleep(8000);
}
}
where i am doing mistake in code ? any error? am beginner i need help
You can't access forms controls in a separate thread. Try this in setvalues():
Invoke((Action)(() => {
webBrowser1.Document.GetElementById("username").SetAttribute("value","admin");
webBrowser1.Document.GetElementById("password").SetAttribute("value","12345");
}));

Focusing a ReportViewer control

I'm trying to set a focus on my ReportViewer control. There are no reports binded to it or whatsoever. I have this code on my Form1_Load event:
private void Form1_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
this.reportViewer1.Select();
this.reportViewer1.Focus();
if(this.reportViewer1.Focused)
{
Console.WriteLine(true);
}
else
{
Console.WriteLine(false);
}
}
After the form loads, the else block is being executed. Why does that keep happening even though I already made a call to the .Focus() and .Select() functions?

C# Windows Form OnLoad() Event not updating DataGridView.DataSource

So I have this code:
private void frmSell_Load(object sender, EventArgs e)
{
dgvProducts.DataSource = _data.AllProducts();
}
Where _data.AllProducts() returns a List.
The only problem is that line will only work when outside the _Load() event, for example, it will perfectly work when placed inside a buttonĀ“s OnClick()
How can I load de products in the _Load event?

how to generate a SelectionRangeChanged Event Programatically ChartControl WinForms

want to create a selectionRangeChanged event programatically not really getting how to do it
private void btn_10D_Click(object sender, EventArgs e)
{
double varRange = 10;
double var_Sel1 = DatesX[0].ToOADate();
Chart1.ChartAreas["ChartArea1"].CursorX.IsUserEnabled = true;
Chart1.ChartAreas["ChartArea1"].CursorX.IsUserSelectionEnabled = true;
Chart1.ChartAreas["ChartArea1"].CursorX.SelectionColor = Color.LightGray;
Chart1.ChartAreas["ChartArea1"].CursorX.SelectionStart = var_Sel1;
Chart1.ChartAreas["ChartArea1"].CursorX.SelectionEnd = varRange + var_Sel1;
Chart1.ChartAreas["ChartArea1"].CursorX.Position = varRange + var_Sel1;
Chart1.SelectionRangeChanged += new EventHandler<CursorEventArgs>(Chart1_SelectionRangeChanged);
}
void Chart1_SelectionRangeChanged(object sender, CursorEventArgs e)
{
throw new NotImplementedException();
}
thank you
For all events in C# is true that if class creator did not make extra effort to allow event firing form outside of class it is impossible to fire them.
According to MSDN
Chart.SelectionRangeChanged event Occurs when the selection start position or end position is changed.
But from my tests I can see that it is fired only if it is changed by user not program.
If I understand your intention correctly you want to handle those small buttons under your chart and btn_10D_Click method is a click handler for one of them. Try to move this line
Chart1.SelectionRangeChanged += new EventHandler<CursorEventArgs>(Chart1_SelectionRangeChanged);
to your constructor and ensure it is called once (remove it form other handlers). This will ensure your code is executed when user changes selection. If you want to execute same code for your button you should simply extract handler contents to method and call it form button click handler.
void Chart1_SelectionRangeChanged(object sender, CursorEventArgs e)
{
DoSomething(/*some arguments if you need them*/);
}
private void btn_10D_Click(object sender, EventArgs e)
{
\\your code
DoSomething();
}

Categories

Resources