|
And there's a problem again, the "CurrentCell" property's Row and Column are with respect to the Grid View (or that is how it is showing me), because when I sort the DataGrid, the ColumnNumber and RowNumber properties of "CurrentCell" cease to return the original row and column number, they return the new row and column number (with respect to the DataGrid) instead...
- A programmer's national anthem; "AAAAAHHHHH!!!!"
|
|
|
|
|
The following function takes care of the sorting. This will give you the exact datarow no matter whether it is sorted or not.
private DataRow GetDataRowAt(int index)
{
DataRow dataRow = null;
CurrencyManager currencyManager = null;
currencyManager = (CurrencyManager)this.BindingContext[this.dataTable];
if ( currencyManager != null )
{
dataRow = ((DataRowView)currencyManager.List[index]).Row;
}
return dataRow;
}
Live Life King Size
Alomgir Miah
|
|
|
|
|
A very simple way is just to access the DefaultDataView.
Add the code below to the CurrentCellChanged event of the datagrid:
<br />
int currRow = myGrid.CurrentCell.RowNumber;<br />
DataView dv = (DataView)((DataTable)grdProduction.DataSource).DefaultView;<br />
I have used it only with DataTables. I don't know what will happen with other kinds of datasources.
|
|
|
|
|
The problem still remains the same, the problem is that "I don't know what is the index of the row in the DataTable that has been clicked by the user", myGrid.CurrentCell.RowNumber, returns the row number with reference to the DataGrid, not the DataTable, Row#3 in the DataGrid may be any row in the DataTable from 0 to NumberOfRows-1. That's what I have to find, I want to know which row with reference to DataTable has been clicked?
Thank you for the reply...
- A programmer's national anthem; "AAAAAHHHHH!!!!"
|
|
|
|
|
I though you just wanted to have access to the row that got changed. Anyway, the DataRow has an internal method called "GetCurrentRecordNo" which does what you need. The following code shows you how to access an internal method:
<br />
public int GetRowIndexSelected()<br />
{<br />
int rowIndex = -1;<br />
if (grid.DataSource != null)<br />
{<br />
DataView dv = (DataView)((DataTable)grid.DataSource).DefaultView;<br />
DataRowView drv = dv[grid.CurrentCell.RowNumber];<br />
Type t = drv.Row.GetType();<br />
MethodInfo mi = t.GetMethod("GetCurrentRecordNo", BindingFlags.NonPublic | BindingFlags.Instance);<br />
rowIndex = (int)mi.Invoke(drv.Row, null);<br />
}<br />
return rowIndex;<br />
}
By the way, to figure out what method to use, I used Reflector[^]
|
|
|
|
|
Thanks a lot for your time... The code has served much purpose...
Thanks Again...
- A programmer's national anthem; "AAAAAHHHHH!!!!"
|
|
|
|
|
i have 2 applications, one is windows application, the other is windows service.
the windows application must start and stop the windows service.
so i neeed to have, a setup that can install both at the same. the windows application must start and stop the service.
is that possible ?
i have other question, when i desinstall the program can it stop the service and desinstall the windows service and the windows application?
my purpose is to make a program, that uses windows service, controlled by windows application.
Thanks for helping
|
|
|
|
|
http://www.c-sharpcorner.com/WindowsServices.asp
has loads of info u need.
Live Life King Size
Alomgir Miah
|
|
|
|
|
Hi all,
My requirement is to develop a Windows Control Library in C# and use that control in COM Client (VB6). Well! I was able to do all these succssfully. But while clicking TAB key on my control, when it is displayed in the COM Client, it does not behave as expected. ie, it is not moving it focuses to the next control. It doesn't look like it is recognizing the TAB key click event. I understand that it is a problem with message loop that the .NET control uses and the message loop that the COM client application provides are fundamentally different.
How can I solve this problem? Please suggest me some code snippets.
Thanks in Advance!!!
Sivakumar R
|
|
|
|
|
Sorry I can't help you but can you tell me how you created the COM object using C#? A while ago I tried it and I could only create a COM+ which was not visible from VB6, so I ended up creating my COM using VB.net instead of C# because the COM class was available only in VB.net.
Thanks,
Rudy.
|
|
|
|
|
I meant, using COM Interop I have imported the .C# component to COM component. These are the steps to create the COM Interop component in C#
1. Create a class library or windows control library project.
2. Add the required methods.
3. Goto Project-> Propeties and select Build
4. Check Register for COM Interop option
5. Compile the project
6. use the regasm.exe utility to register create type library and register the components with /codebase switch
(ex : >regasm mycontrol.dll /tlb:mycontrol.tlb /codebase
7. Now the assembly is registered in your system.
8. Open the vb project and add reference for this component.
9. Now you can access the .NET component in vb6 as if you access other components.
Thanks
Sivakumar R
|
|
|
|
|
Thanks for the reply.
I followed your steps and was able to create the COM; however, I can't see any of the methods of my COM object in VB6. I can only see the class.
In vb.net this happened if I didn't declare the COMClass attribute which specifies the GUIDs for classId, interfaceId, and eventsId. Don't I need the same in C#?
Thanks,
Rudy.
|
|
|
|
|
Hello,
I get an exception when press Ctrl+C in my DataGrid, however, if I right click the grid, and pick Copy from a menu, everything works fine. Any ideas? Here is the exception:
The current thread must set to Single Thread Apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
************** Exception Text **************
System.Threading.ThreadStateException: The current thread must set to Single Thread Apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
at System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean copy)
at System.Windows.Forms.Clipboard.SetDataObject(Object data)
at System.Windows.Forms.DataGrid.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.TextBoxBase.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.ThreadContext.System.Windows.Forms.UnsafeNativeMethods+IMsoComponent.FPreTranslateMessage(MSG& msg)
|
|
|
|
|
I may be waaaay out in left field here, but have you tried applying the STAThreadAttribute to your Main function?
|
|
|
|
|
|
And you still get the error? Does it error on all types of cell data?
|
|
|
|
|
Yeah I still get the error, by the way do you place STAThreadAttribute before all your methods in the class?
|
|
|
|
|
should just be as follows:
[STAThread]
public static void Main(...
or
[STAThreadAttribute]
public static void Main(string[] args)
If the clr is initializing COM before your main is called, or you're firing off your form in a newly created thread, it may not work correctly.
|
|
|
|
|
Hello gurus,
I would like to know how to find and activate or (re)open a document in an MDI application by double clicking on the tree leaf?
I have stored the document's path in a treeview and when selecting a leaf that correspond to the document, I wish to activate the window if it's already opened or (re)open it if necessary by double clicking the leaf (how to detect that properly?). See what I mean? If so, how to do that?
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
if all you need that if the document was just activate it and ifnot open new one
you can store the value of opened document (paths) in your case into hashtable when the user click treenode chech the path if found just activet it if not open it
and don't forget to remove this value from hashtable when
you close the document
Or your question about how to open and activate the document?
MCAD
|
|
|
|
|
Hello,
I guess you know VS .NET... When you double click on a file name via the Solution Explorer, if the document is already opened, the IDE put the window to the front. If the document is not opened, the IDE opens it. When you select an opened document, the IDE actializes the Solution Explorer and selects the correct leaf to reflect which document has been brought to front.
I wish to do a similar behaviour in my application. My application handles several types of documents. I wish to build the same behaviour as VS .NET: when I double click on the treeview leaf, it opens the document if it does not exists or brigs it to front if it exists. If we select an mdi child, it actualizes the treeview. See what I want to do?
How to code this???
Fred.
There is no spoon.
|
|
|
|
|
He told you how to do that in his previous post - use whatever your criteria is for document uniqueness (i.e. path) as a key in a hashtable with the value being a reference to your mdi kid. When the abuser clicks on one of your leafs, check the hashtable for the existance of the key, if a value is found, make sure it's still valid, then call that mdi child form to the front, otherwise create a new mdi child as normal then register it in your hashtable.
|
|
|
|
|
As I said to you use hashtable to demonstrate this
in case you have treeview and tabcontrol like VS
it acttually not standerd tab but no problem
You can easly modify this to work with forms instead of tabcontrol and tabpages
HashTable ht=null;
and in form load event you init the Hashtable
ht=new HashTable(); ;
now suppose the user double click on tree view
if the tabcontrol have tabpage select it if not add new one
private void treeView1_DoubleClick(object sender, System.EventArgs e)
{
if(ht.Contains(treeView1.SelectedNode.Text))
{
tabControl1.SelectedTab=(TabPage)ht[treeView1.SelectedNode.Text];
}
else
{
TabPage newTab=new TabPage();
newTab.Text=treeView1.SelectedNode.Text;
tabControl1.TabPages.Add(newTab);
ht.Add(treeView1.SelectedNode.Text,newTab);
}
}
MCAD
|
|
|
|
|
Thanks
I have found that way:
<br />
private bool FindChild(string caption)<br />
{<br />
foreach (Form frm in MdiChildren)<br />
if (frm.Text == caption)<br />
{<br />
frm.BringToFront();<br />
return true;<br />
}<br />
return false;<br />
}<br />
Is it valuable? At least, it works fine too
Fred.
There is no spoon.
|
|
|
|
|
How can i set a value to a property of an object inheritant MarshalByRefObj at client side
|
|
|
|