|
|
|
Hi,
I would like to obtain the UITypeEditor for an object in C#. I looked at TypeDescriptor.GetEditor() but i'm not sure what it wants in the 'editorBaseType'. Does it want ' typeof(System.Drawing.Design.UITypeEditor)'? No matter what I do I always get 'null' returned.
Anyway, the reason I want to do this is I want to know the UITypeEditor used for a standard Boolean object so I can use it as the editor for my own custom boolean type. How can I find this?
Regards,
Shane
|
|
|
|
|
Look at the sample code Here.[^]
Although it's main purpose is to show how to create different shape controls, it has a very well documented code that shows how to create UITypeEditors.
|
|
|
|
|
Hi there,
Thanks for the reply, but I don't need to know how to write UITypeEditors, i've written plenty. It's more that I wanted to know how to obtain the UITypeEditor for the 'Boolean' type.
In any case, i've worked it out. The standard Boolean type converter supports standard values so they are expressed via a drop down box in the propertygrid.
Shane
Shane Stevens
Technical Director
Blue Tongue Entertainment
www.bluetongue.com
|
|
|
|
|
Hello,
I need to find out which row (in the DataTable) has been clicked by the user in the DataGrid. I know I can use HitTest() method of DataGrid, but that is for row and column in the DataGrid, not the DataTable i.e. If the user has sorted the records in the DataGrid, the row idices may be different from those in the DataTable.
e.g. if the user has sorted the records, Row 3 may be Row 0 in the DataTable, so I can't blindly go for Row 3 in the DataTable, I need to be sure of the actual row that has been clicked.
Any Ideas?
Thanks in Advance...
- A programmer's national anthem; "AAAAAHHHHH!!!!"
|
|
|
|
|
read the rowid value from grid you clicked
and search by this id in datatabe some thing like that
string IdVal=GetIDFromCell();
dataSet21.Customers.FindByCustomerID(valId);
MCAD
|
|
|
|
|
Can you please elaborate a little more?
Where are these functions to be defined, how are they to be implmented, etc...
- A programmer's national anthem; "AAAAAHHHHH!!!!"
|
|
|
|
|
Found this on Windows Forms FAQ (quoting verbatim without permission):
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q934q
... but if the grid has been sorted, you can no longer get at the current row in the table through the grid's CurrentRowIndex. But for both unsorted and sorted grids, you can get at the current row through the BindingContext and the Current property of the BindingManagerBase.
[C#]
BindingManagerBase bm = this.dataGrid1.BindingContextr[this.dataGrid1.DataSource, this.dataGrid1.DataMember];
DataRow dr = ((DataRowView)bm.Current).Row;
[VB.NET]
Dim bm As BindingManagerBase = Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember)
Dim dr As DataRow = CType(bm.Current, DataRowView).Row
Me again. I've noticed that if my BindingManager is disconnected (e.g. bm.SuspendBinding() ) that this throws a wonderful exception. I wrap this in a try/catch block or check that bm.Current > -1.
robrich
|
|
|
|
|
private int currentGridRow = 0;
private int currentGridColumn = 0;
private void OnGridCurrentCellChanged(object sender, EventArgs e)
{
DataGridCell dataGridCell = this.dataGridAllocation.CurrentCell;
//Update Member Variables
this.currentGridRow = dataGridCell.RowNumber;
this.currentGridColumn = dataGridCell.ColumnNumber;
}
private void OnGridMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//Get Current Point
this.hitTestGridInfo = this.dataGrid.HitTest(new Point(e.X, e.Y));
if (hitTest.Type == DataGridEx.HitTestType.Cell )
{
DataRow row = GetDataRowAt(this.currenGridRow);
}
}
}
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
|
|
|
|
|
Thanks a lot for such a valuable advice, just one more question, why do we need to manually keep track of the current Row and Column, can't we use "CurrentCell" property directly in the OnGridMouseDown()?
- A programmer's national anthem; "AAAAAHHHHH!!!!"
|
|
|
|
|
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?
|
|
|
|