|
Hi
I want to create a c# program and i have a question:
How can I end a process that running in CPU?
Thanks.
|
|
|
|
|
Get it's Process instance from Process.GetProcessByName (or whatever your need requires) and call its CloseMainWindow method, or (more risky) its Kill method.
Process class docs[^]
|
|
|
|
|
just to kill the process.
BOOL TerminateProcess(
HANDLE hProcess,
UINT uExitCode);
when a process that running in CPU,i don't think we can end it.You just need to use the TerminateProcess function,then the system will end it.
|
|
|
|
|
hi
i am using vs.net 2005 C# to load a excel file into a window form webbrowser control in a window form, however i notice that when i navigate the excel into the webbroser the excel.exe application is actually hidden in the background, which i am fine with, but when i try to open another excel file it always loads into the already opened but hidden application, which means while the webbrowser is displaying excel file A, i cant open another excel file B .
is there any way to work around this?
|
|
|
|
|
Hi Guys,
I am having an issue with the Windows User Contol communication. I am creating a winform application. I have a tree view in the page (UC1). I am populating data to that from DB. on the leaf node select, i have to call an even in a Grid (User Control2) which will populate the data depending on the selection of the treenode text. Here the Tree & Grid are usercontrols. I have tried to use events for doing the same. But there are issue, If any one can help me, i will be thankful to them
Hi Guys,
Thanks for your response. This is what i am trying to do.
GridUser Control.cs
public partial class LogGridViewUserControl : UserControl
{
public delegate void Data_Bind(object sender, LogGridEventArgs e);
public event Data_Bind dataBindHandler;
public LogGridViewUserControl()
{
InitializeComponent();
}
public void OnDataBind(Object sender, LogGridEventArgs e)
{
if (dataBindHandler != null)
{
string str = CallBusiness(e.Connection);
}
}
}
public class LogGridEventArgs
{
public string Connection { get; set; }
public LogGridEventArgs(string connection)
{
Connection = connection;
}
}
TreeUserControl.cs
public partial class TestTreeControl : UserControl
{
public TestTreeControl()
{
InitializeComponent();
// BuilTree()
}
private void trvTest_NodeSelect(object sender, TreeViewEventArgs e)
{
if (e.Node.Nodes.Count == 0)
{
I need to call the OnDataBind event in the Grid to populate the data in the Grid
}
}
}
In the main form, i will add the both user controls. How do i call the OnDataBind evnthandler of the GridView when a node selection is changed in the treeview. I am not an expert in the Winform development/ not so good with delegates. If any one can chip in, it will be of great help to me.
Thanks
Tutu
|
|
|
|
|
I'm not quite sure what you want but I think you may have it the wrong way around. Try creating a NodeSelected event in the TestTreeControl control and then fire the event where you need to call the OnDataBind method.
Then in the main form subscribe to that event (see pseudo code below)
MyTestTree.NodeSelected += new NodeSelectedDelegateHandler(MyTestTree_NodeSelected);
void MyTestTree_NodeSelected(object source, LogGridEventArgs e)
{
MyLogGridViewUserControl.OnDataBind(source, e);
}
Also your LogGridEventArgs class should inherit from EventArgs
Cheers
Architecture is extensible, code is minimal.
|
|
|
|
|
Hello,
I need to develop a WinForm application which can play .mp3 music files.
I want to have complete control over the UI - no visibly embedded Media Player if possible.
I also need to be able to programatically stop/play/pause/resume/change volume/change songs.
Any ideas on how to do this?
Thanks,
Roy.
|
|
|
|
|
This[^] video might help you.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
Hi,
Thanks for the link. it helped.
|
|
|
|
|
hi i am using vs 2005 c# to make a simple window form which can load an excel file INTO the window form. and then manipulating the loaded excel with interlop
i have tried using webbrowser at How to Integrate Excel in a Windows Form Application using the WebBrowser[^]
however instead of loaded into the webbrowser it always open into the whole file instead of into the webbrowser.
does anyone mind suggesting an alternative or how to solve the webbrowser problem?
|
|
|
|
|
|
prerakpatel wrote: How to Integrate Excel in a Windows Form Application using the WebBrowser[^]
He already define this link and searching how to recover from problem which occur in WebBrowser.
|
|
|
|
|
neodeaths wrote: does anyone mind suggesting an alternative
Here[^] it is
I are Troll
|
|
|
|
|
Hi folks.
I need a little inspiration.
I want to program a Windows program that can display a calendar in the desktop background. It should be possible to interact with this calendar (add appointments etc).
I know there are other programs that do this very well (eg. Active Desktop Calendar http://www.xemico.com/adc/) but my program must have some other features than the alternatives currently on the market.
I plan to make it an open source project.
My biggest problem is how to go about it grapples with creating an interactive desktop background? Anyone who has tried it or have experience with something similar? Possibly a link to some guides, or some API names that I should look at?
I have experience in C #, C + +, C, Java, Visual Basic. But I am also willing to look at another programming language if it can solve my problem in a better way. I'm not looking for a sidebar solution.
Hope you can help.
|
|
|
|
|
hansdam wrote: or some API names that I should look at?
SetWindowPos with HWND_BOTTOM
I are Troll
|
|
|
|
|
I have my filtered combo boxes working in a datagridview thanks to a Linda Liu sample. Now when I enter a row I want to see the data from a row in a sequence of text boxes below the grid - but for the combo boxes I only see the index, when I would prefer to see the information e.g. route description. Here is a cutdown version of From1.h:
namespace DataGridViewComboEx5 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Collections::Generic;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::DataGridView^ gridPassenger;
private: System::Windows::Forms::DataGridViewComboBoxColumn^ dgRoute;
private: System::Windows::Forms::DataGridViewComboBoxColumn^ dgStage;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dgPerson;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ lblPerson;
private: System::Windows::Forms::Label^ lblStage;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ lblRoute;
private: System::Windows::Forms::Label^ label5;
:
:
ref class ViewPassengerData
{
private:
int m_Route;
int m_Stage;
String ^m_Person;
public:
ViewPassengerData(int Route, int Stage, String^ Person)
{
m_Route = Route;
m_Stage = Stage;
m_Person = gcnew String(Person);
}
property int RouteID
{
int get()
{
return m_Route;
}
void set(int value)
{
m_Route = value;
}
}
property int StageID
{
int get()
{
return m_Stage;
}
void set(int value)
{
m_Stage = value;
}
}
property String^ Person
{
String^ get()
{
return m_Person;
}
void set(String^ value)
{
m_Person = value;
}
}
};
private:
List<ViewPassengerData^> ^m_DataList;
DataSet ^RouteStages;
DataTable ^dtRoute;
DataTable ^dtStages;
BindingSource ^bsRoute;
BindingSource ^childBS;
BindingSource ^filteredStages;
bool m_LoadComplete;
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
m_LoadComplete = false;
RouteStages = gcnew DataSet();
dtRoute = gcnew DataTable("dtRoute");
dtStages = gcnew DataTable("dtStages");
bsRoute = gcnew BindingSource();
childBS = gcnew BindingSource();
filteredStages = gcnew BindingSource();
DataColumn ^col = gcnew DataColumn("RouteID", int::typeid);
dtRoute->Columns->Add(col);
col = gcnew DataColumn("RouteDescription");
dtRoute->Columns->Add(col);
col = gcnew DataColumn("StageID", int::typeid);
dtStages->Columns->Add(col);
col = gcnew DataColumn("StageDescription");
dtStages->Columns->Add(col);
col = gcnew DataColumn("RouteID", int::typeid);
dtStages->Columns->Add(col);
RouteStages->Tables->Add(dtRoute);
RouteStages->Tables->Add(dtStages);
DataRow ^row = RouteStages->Tables["dtRoute"]->NewRow();
row[0] = 3;
row[1] = "Route 3";
RouteStages->Tables["dtRoute"]->Rows->Add(row);
row = RouteStages->Tables["dtRoute"]->NewRow();
row[0] = 2;
row[1] = "Route 2";
RouteStages->Tables["dtRoute"]->Rows->Add(row);
row = RouteStages->Tables["dtStages"]->NewRow();
row[0] = 44122;
row[1] = "Stage 1";
row[2] = 3;
RouteStages->Tables["dtStages"]->Rows->Add(row);
row = RouteStages->Tables["dtStages"]->NewRow();
row[0] = 53404;
row[1] = "Stage 2";
row[2] = 3;
RouteStages->Tables["dtStages"]->Rows->Add(row);
row = RouteStages->Tables["dtStages"]->NewRow();
row[1] = "Stage A";
row[2] = 2;
row[0] = 60601;
RouteStages->Tables["dtStages"]->Rows->Add(row);
row = RouteStages->Tables["dtStages"]->NewRow();
row[0] = 94105;
row[1] = "Stage B";
row[2] = 2;
RouteStages->Tables["dtStages"]->Rows->Add(row);
bsRoute->DataSource = RouteStages;
bsRoute->DataMember = "dtRoute";
childBS->DataSource = RouteStages;
childBS->DataMember = "dtStages";
filteredStages->DataSource = RouteStages;
filteredStages->DataMember = "dtStages";
this->dgRoute->DataSource = bsRoute;
this->dgRoute->DisplayMember = "RouteDescription";
this->dgRoute->ValueMember = "RouteID";
this->dgStage->DataSource = childBS;
this->dgStage->DisplayMember = "StageDescription";
this->dgStage->ValueMember = "StageID";
DataTable ^dtViewPassengerData = gcnew DataTable("ViewPassengerData");
dtViewPassengerData->Columns->Add("RouteID", Int32::typeid);
dtViewPassengerData->Columns->Add("StageID", Int32::typeid);
dtViewPassengerData->Columns->Add("Person", String::typeid);
DataRow ^dr = dtViewPassengerData->NewRow();
dr["RouteID"] = 3;
dr["StageID"] = 44122;
dr["Person"] = "Thomas";
dtViewPassengerData->Rows->Add(dr);
dr = dtViewPassengerData->NewRow();
dr["RouteID"] = 2;
dr["StageID"] = 60601;
dr["Person"] = "Edward";
dtViewPassengerData->Rows->Add(dr);
gridPassenger->AutoGenerateColumns = false;
gridPassenger->DataSource = dtViewPassengerData;
gridPassenger->Columns[0]->DataPropertyName = "RouteID";
gridPassenger->Columns[1]->DataPropertyName = "StageID";
gridPassenger->Columns[dgPerson->Index]->DataPropertyName = "Person";
m_LoadComplete = true;
}
private: System::Void gridPassenger_CellValueChanged(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
if ((e->ColumnIndex == dgRoute->Index)
&&(e->RowIndex>= 0))
{
if (gridPassenger->DataSource->GetType() == DataTable::typeid)
{
gridPassenger->Rows[e->RowIndex]->Cells[dgStage->Index]->Value = DBNull::Value;
}
else
{
gridPassenger->Rows[e->RowIndex]->Cells[dgStage->Index]->Value = nullptr;
}
}
}
private: System::Void gridPassenger_DataError(System::Object^ sender,
System::Windows::Forms::DataGridViewDataErrorEventArgs^ e) {
if (e->ColumnIndex != dgStage->Index)
{
MessageBox::Show("Data error occurs:" + e->Exception->Message);
}
}
private: System::Void gridPassenger_EditingControlShowing(System::Object^ sender, System::Windows::Forms::DataGridViewEditingControlShowingEventArgs^ e) {
if (this->gridPassenger->CurrentCell->ColumnIndex == dgStage->Index)
{
DataGridViewComboBoxEditingControl ^control = dynamic_cast<DataGridViewComboBoxEditingControl^>(e->Control);
BindingSource ^bs = dynamic_cast<BindingSource^>(control->DataSource);
if (bs != nullptr)
{
(dynamic_cast<ComboBox^>(e->Control))->DataSource = filteredStages;
Object ^Routevalue = this->gridPassenger->Rows[this->gridPassenger->CurrentCell->RowIndex]->Cells[dgRoute->Index]->Value;
if (Routevalue == DBNull::Value || Routevalue == nullptr)
{
filteredStages->Filter = "RouteID=-1";
}
else
{
filteredStages->Filter = "RouteID=" + Routevalue->ToString();
}
if (this->gridPassenger->CurrentCell->Value != DBNull::Value
&& this->gridPassenger->CurrentCell->Value != nullptr)
{
control->SelectedValue = this->gridPassenger->CurrentCell->Value;
}
}
} }
private: System::Void gridPassenger_RowEnter(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
if (m_LoadComplete&& e->RowIndex < gridPassenger->RowCount)
{
lblPerson->Text = gridPassenger->Rows[e->RowIndex]->Cells[dgPerson->Name]->Value->ToString();
lblRoute->Text = gridPassenger->Rows[e->RowIndex]->Cells[dgRoute->Name]->Value->ToString();
lblStage->Text = gridPassenger->Rows[e->RowIndex]->Cells[dgStage->Name]->Value->ToString();
}
}
};
}
Ger
modified on Wednesday, December 8, 2010 11:44 PM
|
|
|
|
|
When you have code like this, please wrap the block of code in a <pre> </pre> tags. It makes it easier to read.
|
|
|
|
|
Done - wasn't aware of them - and I've chopped out much of the autogenerated code.
Ger
Ger
|
|
|
|
|
Ger Hayden wrote: wasn't aware of them
See point 7 in the Forum Guidelines[^].
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
In the 24 hours since my original post I have made no progress and huge progress. None in that the problem persists, but I have learned volumes about how the combo column behaves.
Here is my original post:
My application reads bus routes into a combo column on a datagrid view. For each Route the Stages column is reloaded.
Each Passenger on Route 1 has its correct stage displayed, but the grid fails to show the stages for passengers on Route 2.
When I step through the code, I can see the Stage column reload and the correct stage picked from the list for Route 2, but its never shown. Not only that, it throws in the Datagrid View Default Error Dialog for good measure.
I am using VS2008, C++/CLI grid is entirely unbound and I am not employing datasoures, so setting displaymember/valuemember is not available to me.
void VTPassenger::frmPassengerMaster::Load_RouteStages(int arg_Route_ID)
{
dgStage->Items->Clear();
dgStage->Items->Add("0 <--- Undefined --->");
// then the Stages for this Route
List<CRouteStage^>^ RouteStageList = gcnew List<CRouteStage^>();
try
{
RouteStageList = CComs_RS::Fetch_RouteStage(m_LocalConnection,1,arg_Route_ID);
}
catch(Exception ^e)
{
String ^MessageString = " SQL Error retrieving Route Stages: " + e->Message;
MessageBox::Show(MessageString, "RouteStage Techincal Error");
return;
}
if (RouteStageList->Count == 0)// No records so no Ticket types defined
{
return;
}
for each(CRouteStage^ candidate in RouteStageList)
{
array<Object^>^ itemRec = gcnew array<Object^> {candidate->p_Stage_ID,
candidate->p_StageName
};
String^ AddString;
AddString = String::Format("{0} - {1}", candidate->p_Stage_ID, candidate->p_StageName);
this->dgStage->Items->Add(AddString);
}
}
And now for the progress.
This will work very well as is if the passenger list is sorted in route order, but do not consider this a suitable workaround. Learning that forced me to reflect on the design. For five hundered passengers distributed over a pair of short routes, 500 database visits doesnt make sense for essentially the same route stages - but what if there were 300 routes involved for our little outfit? Then front loading and holding 300 sets of route stages in a collection in memory doesn't sit well.
So programmatically I have created a datatable and read in my route stages upon which I attempted a filter in the sytle of spidernet's DataGridView FAQ bound in the code to the datatable, but changing the contents of the filter for each route change plus searching the list threw up issues.
So now I have two choices - a collection of filtered stage sets, one per route which will work well while the number of routes operated is low, or expand on my original idea but attempt to implement it a cell level - where I have just commenced research.
Ger
modified on Tuesday, November 30, 2010 11:51 PM
|
|
|
|
|
If users rarely make a selection from the combo then only request the data when the user edits the cell. This may or may not be acceptable.
You may also want to cache the results in a HashTable (route, collection of stages) so before you request the data, see if it already exists in the HashTable. If so, you will be able to access the data in the HashTable and avoid the round trip to the DB.
|
|
|
|
|
Thanks Robert.
I found an example that is very similar to your second suggestion. See my next post for details on how I applied it.
Ger
Ger
|
|
|
|
|
I have a textbox, a standard button and a toolstrip containing a couple of buttons.
In the validating event of the textbox i coded to check whether it is blank.
If yes then it shows a message 'Enter Value'. When the standard button is clicked while
the textbox is empty, it's validating properly and showing the message but when the
toolstripbutton is clicked it's not not validating the textbox and no message is being
shown. It seems that I gotto write the validation code explicitly in the
toolstripbutton_click event which is too troublesome when there are multiple textboxes
and toolstripbuttons on a single form. What I want to know is whether the
textbox_validating can be fired while the toolstripbutton is clicked?
Handling toolstrips is really a headache.
Please help. I'm badly in need of it. Regards.
|
|
|
|
|
This is an undocumented feature and appears to be by design. (don't you just hate that terminology) I guess it makes sense in a non-OOP way. When an event in the ToolStrip is raised, the control within the form that has focus, does not lose that focus! Therefore the validated/validating events of the control that has focus, are not raised.
The approach I take is to refactor each validation and provide a method that calls all validations within a single method. It's nice to provide control by control validation but there is no guarantee that a control will ever gain or lose focus. You need an overall validation method to handle this.
If your dealing with an underlying data source you may also want to look at the IDataErrorInfo interface.
|
|
|
|
|
priyamtheone wrote: Please help. I'm badly in need of it
Oh! your question will be more clear when you mention your code so please mention it.
whatever,
you can create a function and call it as many time you want to perform it. you don't need to create command every time for same work.
|
|
|
|