UltraGrid Filter cell property - c#

Working on a code that was written by someone else. Here are the important parts of the code:
UltraGridColumn col = columns.Add("FolderImage", "Status");
col.Header.Fixed = true;
col.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.False;
There is more code written to specify the behavior of the folder, but it is irrelevant for the example; As of right now, the following result is generated:
As you can see, there is a greyed out "Filter" button, and the pin is missing:
I want it to look like this:
I.e. filter button needs to go in the status column (it just needs to be blank), and the pin button should be enabled. According to the Infragistics manual, the code above should produce the very results I am looking for, but it does not.

To hide the filter operator (the 'A' letter) you need to set FilterOperatorLocation of the column to Hidden. To show the pin of the fixed column you need to set to its header FixedHeaderIndicator to Button (by the way this is default value, so if you did not override it at some other place you may skip this step). Try to use code like this:
col.FilterOperatorLocation = FilterOperatorLocation.Hidden;
col.Header.FixedHeaderIndicator = FixedHeaderIndicator.Button;

For the "A" button in a cell, the following code fixed it:
col.FilterOperatorLocation = FilterOperatorLocation.Hidden;
For the pin, I had to enable the "UsedFixedHeaders" property:
this.gridName.DisplayLayout.UseFixedHeaders = true;

Related

.NET WPF WebBrowser Control: Insert HTML at ControlRange selection

I have a WebBrowser control that I am using to create an HTML editor, and I need to be able to insert a string of HTML at the current selection in the document.
Generally, I can do something like this to paste HTML at the current selection, if the selection is a text selection:
IHTMLSelectionObject selection = webBrowser.Document.DomDocument.selection;
// Assume that selection.type == "Text"
IHTMLTxtRange textRange = selection.createRange() as IHTMLTxtRange;
textRange.pasteHTML(myHtmlString);
However, if the current selection is a ControlRange selection, there doesn't seem to be any direct way to insert/paste HTML at that position.
For example:
// Assume that selection.type == "Control"
IHTMLControlRange ctrlRange = selection.createRange() as IHTMLControlRange;
// This throws an error, as IHTMLControlRange has no pasteHTML method
ctrlRange.pasteHTML(myHtmlString);
I know that I can use the HtmlElement.InsertAdjacentElement method to insert an element before or after another element, but that is very limiting, as sometimes I need to be able to insert raw HTML, rather than needing to create an HtmlElement object for it first.
Is there any way to be able to paste/insert an HTML string at the caret position, or over a ControlRange selection?
I have found a workaround for this problem, at least for my specific use case.
The IHTMLSelectionObject.createRange() method returns dynamic, but it will resolve to either an IHTMLTxtRange or an IHTMLControlRange, depending on what the selection type is.
If selection.type == "Text" or selection.type == "None", it returns an IHTMLTxtRange, and if selection.type == "Control", it returns an IHTMLControlRange.
The following statement works for empty selections and text selections:
DomDocument.selection.createRange().pasteHTML(myHtml);
However, in the case of pasting over a control selection, the above statement won't work by default because the createRange() method will return an IHTMLControlRange, which, as mentioned above, has no createRange() method. However, we would be wanting to overwrite the current selection with the new HTML anyway, so one could assume that it is safe to just clear the selection (delete it) and then paste the HTML at the newly empty selection.
Solution
Something like this should work for all types of selections:
// If we have a control selection, clear the selection
if (DomDocument.selection.type == "Control")
DomDocument.selection.clear();
// Now it is no longer a control selection, but an empty text selection
DomDocument.selection.createRange().pasteHTML(myHtml);
This does feel a bit hacky, but it solves the problem for me.

How to suppress a section programmatically in Crystal Reports?

Is there a way to suppress/hide a section programmatically in Crystal Reports???
I need to suppress a section in Crystal Reports when the Change Text in one textbox
Thanks
Add this below code in your code behind file
CrystalDecisions.CrystalReports.Engine.ReportDocument doc=your reportdocument;
doc.DataDefinition.FormulaFields["yourformulaname"].Text = "your value";
//or you can directly set the visibility of your section from code behind on the basis of your business logic as
doc.ReportDefinition.Sections["sectionnameOrIndex"].SectionFormat.EnableSuppress = true;
Go to section expert.
Select your section.
On the right hand side you will notice a suppress checkbox. Check it.
Right beside the check box label you will see a formula button. Click on it. Now you can see a formula editor to write your logic.
In the formula editor write something like this
if {#yourformula}="1" then
true //hide
else
false //do not hide
{yourformula} can be replaced with any field you like.
If you want to set the value of your formula field from code behind then
CrystalDecisions.CrystalReports.Engine.ReportDocument doc=your reportdocument;
doc.DataDefinition.FormulaFields["yourformulaname"].Text = "your value";
//or you can directly set the visibility of your section from code behind on the basis of your business logc as
doc.ReportDefinition.Sections["sectionnameOrIndex"].SectionFormat.EnableSuppress = true;

How can I hide all code before my function header on the same line as it?

I was looking at the code of C# to create Lists and I noticed they were able to hide, not only comments, but anything else occurring before the function header. On top of this, it was collapsed without a preview, just three dots, on the same line as the function header to conserve space. This is perfect, because I want to conserve space but still have detail comments.
On their code, it was nothing more than:
// Summary:
// Comment
// Comment
public List()
I had copied and pasted what they had done, but go no results.
How can I do this?
You can collapse all your code and then stand on your function header and choose to toggle outlining expansion.
To achieve the described behavior do:
CTRL + M+ O for collapses all definitions
Then stand on your function and click CTRL + M + M to toggle outlining expansion for it.
Here is the result:

Some elements of control not recognized by C# compiler

I have a site that is using the aspdotnetstorefront platform, although this should pertain to any C# site. There is a custom control in a dll named Account. This has several elements including text boxes for customers to enter name, phone number etc.
I have checked the source code with DotPeek and verified I am using the correct naming conventions.
I am attempting to use the javascript onChange event to copy the first name, last name and phone number to lower boxes when a check box (account information same as billing) is checked. So that if customers select that the information is the same it will be automatically copied as they move from one box to the next.
The odd thing is, this works with some of the text boxes but not others. To make things simple I have removed the JS that copies the contents and replaced it with a pop up box for testing.
This works, when I change the text I get a "Hello World" pop up box:
ctrlAccount.txtFirstName.Attributes.Add("onchange", "alert('hello,world')");
But this does not:
ctrlAccount.txtPhone.Attributes.Add("onchange", "alert('hello,world')");
The error I get is:
CS1061: 'AspDotNetStorefrontControls.Account' does not contain a definition for 'txtPhone' and no extension method 'txtPhone'
accepting a first argument of type
'AspDotNetStorefrontControls.Account' could be found
So it looks like the compiler cannot recognize the phone text box. When I look at the rendered page code (When the error has been removed of course) the box is there and the ID is correct.
Reading the source code with DotPeek I see:
public Account()
{
this._txtFirstName = new TextBox();
this._txtLastName = new TextBox();
this._txtEmail = new TextBox();
this._txtPassword = new TextBox();
this._txtPasswordConfirm = new TextBox();
this._txtPhone = new TextBox();
}
private void AssignClientReferenceID()
{
this._txtFirstName.ID = "txtFirstName";
this._txtLastName.ID = "txtLastName";
this._txtEmail.ID = "txtEmail";
this._txtPassword.ID = "txtPassword";
this._txtPasswordConfirm.ID = "txtPasswordConfirm";
this._txtPhone.ID = "txtPhone";
}
(I've removed a bunch of other fields in the interest of readability). But that certainly looks to me like text box for the phone number should have the idea of "txtPhone" and "txtFirstName" and "txtLastName" work just fine, so why would this fail on only the Phone box?
The code you've added to the question show only assignment of IDs and nothing else. I can't see the entire source code of Account control but usually fields with leading underscore are protected or private and, to expose these fields, public properties are used so please check if it's present a public property named txtPhone.
EDIT
ctrlAccount.txtFirstName.Attributes.Add("onchange", "alert('hello,world')");
ctrlAccount.txtPhone.Attributes.Add("onchange", "alert('hello,world')");
Try to press F12 with the caret over txtFirstName or txtPhone on the lines above to see where these property are defined.
P.S.:
Do not confuse the names of id and public properties of a class
It's VS bug, simple restart should help you.
Right-click the txtFirstName part and choose "Go to definition". Ensure that the txtPhone property is defined nearby and is accessible.
If you open your project on visual studio, you can right click on txtPhone or txtFirstName and click on "Go to definition". It will take you to the place where it is defined. Maybe txtFirstName is being read from somewhere else where txtPhone does't exist.
I get these kind of warning(not an error) on my application sometimes in compiler however on run time, it recognise the definition and no problem is caused.

Checkboxlist + getting id's of all the checkboxes

How do I get the id's of all the checkboxes generated by a checkboxlist, with datatable as its data source?
I think I have to use the "OnDataBinding" event of the checkbox list, but I don't see how that will help me.
I am using C#
I don't think getting the id's of all the check boxes generated by the check box list is possible, so I think going the moo tools way is the right thing to do.
Any ideas?
Thanks
Ideally you would want to just attach the click event handlers to all your checkbox lists in the domReady event and this will create a much simpler function with MooTools. However, you can keep your code as-is if you prefer and just make your 2 functions a little simpler.
function ToggleSelection(ctrl, sender) {
var checkboxes = $(ctrl).getElements('input[type=checkbox]');
checkboxes.set('checked', sender.checked);
}
function ToggleSelectAll(ctrl, sender) {
var fAllChecked = ($(sender).getElements('input:checked').length == $(sender).getElements('input[type=checkbox]').length)
$(ctrl).set('checked', fAllChecked);
}
You can set the properties of your entire ELements array at once, you don't need to loop through them. In the 2nd function, I'm checking the number of elements that are checked against the total number of checkboxes and if they match that means they are all checked.
Are you using VB or C#..please tag accordingly
You can have List or string called strchklist
VB.NET
For Each li In CheckBoxList1.Items
If li.Selected Then
strchklist += li.Id
End If
Next
C#
foreach (ListItem li in CheckBoxList1.Items){
If li.Selected
strchklist += li.Id ;}
The <asp:ListItem> is not really a Control itself therefore has no ID. If you want to access it in client script add a new attribute you can reference. (yes, during OnDataBinding) Remember that these are not persisted in the ViewState however!
What exactly are you trying to accomplish? May help to elaborate somewhat.
Completely different answer...
The CheckBoxList is a bit of an odd duck... unlike other controls, it does not really have a logical mapping to an obvious HTML construct. It actually renders multiple checkboxes with derivative IDs. Those IDs seem to be generated as CheckBoxList.ClientID + "_" + ItemIndex.
You can verify this by looking at the page source. Internally, it seems the ID of the individual checkbox control is just its index, and then it's rendered with the CheckBoxList as its NamingContainer. You can use Reflector is see how the CheckBoxList control renders the output.
Still a good spot for jQuery. Just easier now you know the IDs.
I woke up this morning and thought of doing this (cblUSEquities is a checkbox list)
cblUSEquities.Attributes.Add("onclick", "javascript:alert('Clicked');");
This adds the alert to the table that the checkbox list generates. One thing to note is, the alert shows up twice If I click the text of the checkbox and once if I click the checkbox. I think this solution will work for me.
BTW, I never thought that the above code would work...
P.S Answering my own question because I wanted to write some code, which I cannot do using the comment box.
In the spirit of StackOverFlow, I arrived to something which works in my scenario but the description of the question is different? What do I do? Edit the question and mark this as answer?
I was able to do this by using mootools and this is the code.
function ToggleSelection(ctrl, sender)
{
var cblCtrl = $(ctrl);
var Allcbs = cblCtrl.getElements('input');
for(var i=0; i<Allcbs.length; i++)
Allcbs[i].checked = sender.checked;
}
function ToggleSelectAll(ctrl, sender)
{
var AllTrueCount = 0;
var cblCtrl = $(ctrl);
var Allcbs = sender.getElements('input');
for(var i=0; i<Allcbs.length; i++)
if(Allcbs[i].checked)
AllTrueCount++;
if(AllTrueCount == Allcbs.length)
cblCtrl.checked = true;
else
cblCtrl.checked = false;
}
C# code which calls the javascript functions
//Binding event to the checkbox list
cblUSEquities.Attributes.Add("onclick", string.Format("javascript:ToggleSelectAll('{0}', this);", chkAllUSEquities.ClientID));
//binding event to the select all checkbox
chkAllUSEquities.Attributes.Add("onclick", string.Format("javascript:ToggleSelection('{0}', this);", cblUSEquities.ClientID));
As it turns out I did not need to know the id's of all the checkboxes generated by the checkbox list. I was able to add the onclick javascript to those checkboxes by this line
cblUSEquities.Attributes.Add("onclick", string.Format("javascript:ToggleSelectAll('{0}', this);", chkAllUSEquities.ClientID));
Which will add the onclick event to the table that the checkbox list generates.

Categories

Resources