|
Yes, I understand that.
WhatI'm wondering is how to interact to COM in the working thread not as a new instance.
Maybe I could find something in articles you shown me here.
Best,
Ken
|
|
|
|
|
Hello!
I have a problem with the DataGrid Control in C#.
I've a form with some textboxes on it. In these textboxes you can search for Data.
If you enter something in a Textbox and press the Search-Button then I build a dynamic SQL-Statement like "Select * from Company where CompanyName like "%Test%"".
With this Select Statement I fill my Dataset.
If the DataSet returns 1 Row then the Row is Displayed in the Textboxes.
If more than 1 Row is found then I open a new form and pass him the DataSet build with the SQl-Statement.
In this new form (form2) I Bind the DataGrid to the Datatable and the Data is displayed well.
In form2 the user can select one DataRow and return to form1 where the selected row is displayed. Therefore form2 returns the index of the row in the Datatable in the Dataset.
Everything works fine until you use the sort possibility in the Datagrid.
After that the DataTable and the DataGrid are not longer synchronus.
I've searched the web and found something about the CurrencyManager and tried with it but without success.
The CurrencyManager.Position only shows the same position that is selected in the Datagrid not in the Position of the DataRow in the DataTable.
Here some of my code:
form1:
frmDisplaySearch frmDisplaySearch_ = new frmDisplaySearch(dsDB,DataTableName);
DialogResult dr_ = frmDisplaySearch_.ShowDialog();
if(dr_.Equals(DialogResult.OK))
{
Console.WriteLine("Ausgewählter Datensatz " + frmDisplaySearch_.SelectedRow);
NoRowSelected = frmDisplaySearch_.SelectedRow;
RowSelected = true;
}
from2:
public frmDisplaySearch(DataSet DataSetIn_,string DataTableNameIn_)
{
InitializeComponent();
DataTableName_ = DataTableNameIn_;
DataSetToDisplay_ = DataSetIn_;
grid.SetDataBinding(DataSetToDisplay_, DataTableName_);
cm_ = (CurrencyManager)this.BindingContext[DataSetToDisplay_,DataTableName_];
this.Text = DataTableName_;
this.grid.Size = new System.Drawing.Size(MaxGridWidth, MaxGridHeight);
AutoSizeCol();
}
private void btnOk_Click(object sender, System.EventArgs e)
{
Console.WriteLine("Ausgewählter Datensatz " + grid.CurrentCell.RowNumber);
Console.WriteLine("Ausgewählter Datensatz cm_" + cm_.Position);
SelectedRow = cm_.Position;
this.DialogResult = DialogResult.OK;
this.Close();
}
|
|
|
|
|
Has no one a hint for me???
|
|
|
|
|
Hallo,
as a workaround, try to get the primary key of the selected row and use it to display the right row in form1.
private void btnOk_Click(object sender, System.EventArgs e)
{
(BindingManagerBase) manager = grid.BindingContext;
(DataRow) row = manager.Current;
string/int id = row[PKColumnName];
this.DialogResult = DialogResult.OK;
this.Close();
}
|
|
|
|
|
Hi guys,
is it anyhow possible to change the backcolor of a specific subitem in a listview? Or is it only possible to change the color of the whole item with ListViewItem.BackColor ?
Likely it won't work without deriving from ListView...
Regards, mYkel
|
|
|
|
|
This Codeproject article, http://www.codeproject.com/listctrl/selectentirerow.asp?target=LVS%5FOWNERDRAWFIXED[^], shows some of what you need, but it's in C++/MFC, not C#!
Basically you need to add the LVS_OWNERDRAWFIXED style to your derived ListView, and handle the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxreference/comboboxmessages/wm_drawitem.asp" target="_blank">WM_DRAWITEM</a> windows message and the corresponding DRAWITEMSTRUCT, which contains the iItemID of the item to draw.
You can add the style to by overriding the ListView's CreateParams property and intercept the WM_DRAWITEM in your overriden DefWndProc . The MSDN says this about LVS_OWNERDRAWFIXED :
"The owner window can paint items in report view. The list-view control sends a WM_DRAWITEM message to paint each item; it does not send separate messages for each subitem. The iItemData member of the DRAWITEMSTRUCT structure contains the item data for the specified list-view item. "
|
|
|
|
|
I have this HTML code, which enables me to log me in to my internet account manager. I want to code this in C#, because it directly leads to a statistics page, and I need them in my program. Does anyone know how I have to code this or could anyone give me some advice?
<form name="TNLogin" method="POST" action="https://www.telenet.be/sys/sso/exec_login.php">
<input name="goto" type="hidden" value="http://www.telenet.be/mijntelenet/index.php?content=https%3A%2F%2Fwww.telenet.be%2Fsys%2Fsso%2Fjump.php%3Fhttps%3A%2F%2Fservices.telenet.be%2Fisps%2FMainServlet%3FACTION%3DTELEMTR%26SSOSID%3D%24SSOSID%24">
<input class="textfield" type="text" name="uid" size="24" border="0">
<input class="textfield" type="password" name="pwd" size="24" border="0">
<input type="submit" value="Aanmelden" border="0" />
</form>
|
|
|
|
|
i have an array of strings that represent filenames with the path. i want to find the last directory that is common between all the files.
ex:
c:\dir1\dir2\abc\abcd\file.ext
c:\dir1\dir2\abc\efgh\file.ext
c:\dir1\dir2\abc\efgh\123\file.ext
the last common directory would be c:\dir1\dir2\abc\
what would be the easiest way to go about this?
thanks,
Rob Tomson
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
Hi,
I need to make sure that a program I distribute can only be run on systems that I have authorized.
I am looking for a piece of code to enumerate a per system unique identifier that is reproducable for this system every time you launch the program and will support Windows 95/98/2000 and above.
Any help is appreciated! Thx,
-Martin-
|
|
|
|
|
You have to make combination of some hardware identites, like HD,CPU id(if its not disable),MAC Address,... there is not one specific unique thing for your computer.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
I have a collection of Items
I Want To select random given numbers from the collection
Without Select an Item Twice
in Other Word If The Collection have 25 items i want to
Select 7 items form it without select an item twice
|
|
|
|
|
I don't think this is best approach,other CPains please correct me:Use Random class to create random numbers and store each number in seprate place and check second time create another number and check if that number is not used before.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
Thanks Mazdak for your Reply
I Thought about Solution Like Yours
That I Create arraylist and store the value and check about
its existig before add item to the arraylist and loop until
I have the selected number but i didn't use this solution
becaus i think that may be lead to infinit loop
In other words what happend if some items in collection never selected and i still need more item i'm not sure if this true all the algorithms
in Random Class Designed to avoid This situation
|
|
|
|
|
What I've done in the past is:
1. Add the objects (numbers in your example) to a collection, so that the collection count is 25 (items 0 through 24).
2. Create a loop to select n items from the collection.
3. On each iteration of the loop, select a random number from zero to collection.Count - 1
4. Retrieve the collection element at the selected index from the collection, then remove it from the collection. The next time the loop iterates, the previously selected item will no longer be selectable, it has been removed from the collection.
There are various optimizations over using a collection, depending on the type of item you're trying to select (reference type, character, integer etc), but the principle is valid, assuming that your original range contained no duplicates.
Hope this helps.
|
|
|
|
|
I'm attemping to create a custom control for the first time and I cannot figure out what I'm doing wrong. I'm attempting to inherit from TreeView using the folowing:
public class HL7TreeView : System.Windows.Forms.TreeView
I've added some properties and Methods and built the new DLL. I then am able to add it to my ToolBox with (Add/Remove ToolBox Item). But when I attempt to drag it into my Designer I get a StackOverflow exception. I've rebooted countless times. I even attempted a UserControl instead of a CustomControl with the same results. Any thoughts ?
I think I might have found the problem....
I commented out the Get and Set command for my properties and the error no longer occurs. Can i not use Gets andf Set with CustomControls ?
|
|
|
|
|
Your Get property probably calls itself, that would be the place to start looking.
|
|
|
|
|
Thanks for the help.
Since this is my first Custom Control i guess I'm not sure how to debug it. I added my HL7TreeView Control Library Project to a test project. Then I added a generic TreeView control to the Windows form. I changed the declaration to use HL7TreeView instead of plain TreeView, but the debgger won't enter my Control Library code. Any hints you can give on debugging a custom control ?
|
|
|
|
|
Hi,
I'm having trouble setting the main form visible from within the child form. I have set the main form to hide (SignatureMain.Hide()).
I then load the child form from within a button on form1:
Treatment.ShowDialog();
On the child form Treatment i try to do the following in an Exit button:
this.ParentForm.Visible = true;
this.Close();
What i'm gettign is the following:
An unhandled exception of type 'System.NullReferenceException' occurred in Signature.exe
Additional information: Object reference not set to an instance of an object.
NOTE:
I have even set the parent form as follows:
Treatment.ShowDialog(this);
This is suppose to set the this (SignatureMain) as the parent to Treatment.
When i run the debbugger and look at ParentForm, its null???
Thanks
|
|
|
|
|
Ok i have figured out the solution. Here it is for anyone looking for the information later.
When loading a form using: myForm.ShowDialog(this) were "this" is the OWNER of the form you are loading, you need to use in the child form the following to get to its properties:
this.Owner.Visible = true; <-- "this" is the child form and i'm accessing the visible property of the parent form (owner).
I'm still not clear as to why Parent and or ParentForm did nto work so if anyone has the answer to that one please post.
Enjoy!
|
|
|
|
|
The Owner or Parent is not immediately available during the creation of the child window/control.
I'm not sure when the reference is exaclty created, but I use the Layout event of the child window with a flag that's set to true when the layout event has been called so the code (or some part of it) in the event handler won't be called again.
<br />
private void Child_Layout....{<br />
if(!flag)<br />
{<br />
flag = true;<br />
}<br />
}<br />
|
|
|
|
|
If I want to draw on a control, is it best to override the OnPaint function or to capture the Paint event?
|
|
|
|
|
When you're inheriting (which you obviously are, since otherwise you wouldn't have the choice) you should override OnPaint . The Paint event exists to notify anyone outside your class that needs to know when you're repainting.
This is true for all the OnXxx protected methods of the class.
Charlie
if(!curlies){ return; }
|
|
|
|
|
To explain why Charlie said what he did (which is correct), overriding is polymorphic, allowing base classes to call your code even though they don't even know about your class. In intermediate language (IL, the code all .NET languages compile to and embedded in assemblies), this instruction uses callvirt instead of simply call . This is much faster to execute and is a good polymorphic design. When you handle events, several - sometimes many - intructions are required to enumerate the delegates for the event (commonly stored in a list after compiling) and to invoke the delegate (late-binding).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hii
i m trying to delete a row using DeleteCommand of DataAdapter, but i can't.
i m using this code..
using System;
using System.Data;
using System.Data.SqlClient;
class ModifyDataTable
{
static void Main()
{
string constr = @"server=(local)\NetSDK;Integrated Security=true;"+
"database=address";
SqlConnection Conn = new SqlConnection(constr);
try
{
string SQL = "SELECT * from Hello";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(SQL,Conn);
DataSet ds = new DataSet();
da.Fill(ds,"Hello");
DataTable dt = ds.Tables ["Hello"];
("Select * From Hello",Conn);
foreach( DataRow r in dt.Rows)
{
Console.WriteLine("{0} {1}",r["Name"].ToString ().PadRight (15),
r["Phone"].ToString ().PadLeft(25));
}
Console.WriteLine("\n" + dt.Rows .Count.ToString ());
da.DeleteCommand = new SqlCommand ("DELETE FROM Hello WHERE (Name='Amit')" ,Conn);
da.Update (ds,"Hello");
Console.WriteLine ("\n" + dt.Rows.Count.ToString ());
foreach( DataRow r in dt.Rows)
{
Console.WriteLine("{0} {1}",r["Name"].ToString ().PadRight (15),
r["Phone"].ToString ().PadLeft(25));
}
}
catch (Exception e)
{
Console.WriteLine ("Error Occured : " +e.Message );
Conn.Close ();
}
finally
{
Conn.Close();
Console.ReadLine ();
}
}
}
This isn't deleting anything neither in the dataset nor in the database
|
|
|
|
|
You should use a DataAdapter when you want your updates and deletes to be managed for you depending on the state of the DataSet .
In your case, you are not altering the <cpde>DataSet, so your delete command is never used.
If you just want to execute a specific delete command:
string sql = "DELETE FROM Hello WHERE (Name='Amit');
SqlCommand comm = new SqlCommand(sql, conn);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
Charlie
if(!curlies){ return; }
|
|
|
|