How to disable tree list rows to be selected in devexpress - devexpress

I have created a tree list for showing the sector and blocks of memory, now I need to disable the selection of root node and also need to disable the rows of blocks which are already occupied, so that only enable rows can be selected from the tree list.
Also the disabled rows text are little bit lighter for the user to differentiate.
Here I am attaching a sample image for the reference, what I need to achieve

Have you considered using TreeList.ShowingEditor event?
Something like this:
void mytreelist_ShowingEditor(object sender, CancelEventArgs e) {
if(mytreelist.FocusedNode.Level == 0 /* root */ || SomeOtherCriteria())
{
e.Cancel = true;
}
}
You can handle TreeList.CustomDrawNodeCell to make a row appear disabled:
private void mytreelist_CustomDrawNodeCell(object sender, CustomDrawNodeCellEventArgs e) {
if(e.Node.Level == 0 /* root */ || SomeOtherCriteria())
{
e.Appearance.ForeColor = Color.Gray;
}
}

Related

Get e parameter from a button that hasn't been clicked

Is there a way that I could access the e event arguments for a button that has not been clicked?
I need to delete multiple entries in a gridview by clicking a button and having it simulate clicking the delete button for each selected entry, but I can't use performClick, so I'm trying to call the actual method that deletes each one. However, that method requires an "e As System.Web.UI.WebControls.GridViewCommandEventArgs" parameter and I can't figure out how to get that.
You won't be able to access the EventArgs parameter.
I'd suggest you design your code like this:
public class MyClass
{
private ListView listView;
protected void OnClick(EventArgs e)
{
performAction();
}
private void performAction()
{
listView.deleteSelectedItems();
}
}
Don't implement functionality you are going to need somewhere else in delegates. Instead call this functionality inside the delegates' body. This way you can reuse performAction() somewhere else ..
Your problem calling delete button can be resolved if you add one check box in each row of datagrid and on click of button Delete you can perform delete operation for the checked rows in following manner
Protected void btnDelete_Click(object sender, EventArgs e)
{
for(int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkDelete = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chkSelect");
if(chkDelete != null)
{
if(chkDelete.Checked)
{
strID = GridView1.Rows[i].Cells[1].Text;
ids.Add(strID); //ids can colletion of any type
}
}
}
}
Now send ids to any function to perform delete.

How to reset ListBox.Rows property to default (without hard coding the default value)

I have an ASP.NET ListBox on a page, and as postbacks occur, I change the items in the list. If there are >= 10 items in the list, I set the Rows property = 10. But if there are less than 10 items, I'd like to set the Rows back to whatever the default value is for Rows.
I see from examining the reflected code that the default value is 4, but I'd rather not hard code it to 4 in my code and instead somehow just reset it to the default.
Is there a way to do this?
You can fetch the default value during the page's Init phase. From the documentation:
In this stage of the page's life
cycle, declared server controls on the
page are initialized to their default
state; however, the view state of each
control is not yet populated.
So you can do something like:
private int _defaultRows;
protected void Page_Init(object sender, EventArgs e)
{
_defaultRows = yourListBox.Rows;
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (yourListBox.Items.Count >= 10) {
yourListBox.Rows = 10;
} else {
yourListBox.Rows = _defaultRows;
}
}

How to select cell with right click in propertygrid

I have a propertyGridControl - how to handle when mouse right is clicked on it - if its clicked on a row but only on the value of the property in this row and not on the cell in which is the name of the property? Now its just raising the rightclick event and not marking the cell.
Such tasks are usually implemented using the control's CalcHitInfo method. It is used to determine the clicked control's area. Here is the code:
private void propertyGridControl1_MouseClick(object sender, MouseEventArgs e) {
if(e.Button == System.Windows.Forms.MouseButtons.Right) {
VGridHitInfo hInfo = propertyGridControl1.CalcHitInfo(new Point(e.X, e.Y));
if(hInfo.HitInfoType == HitInfoTypeEnum.ValueCell) {
propertyGridControl1.FocusedRow = hInfo.Row;
propertyGridControl1.FocusedRecordCellIndex = hInfo.CellIndex;
propertyGridControl1.FocusedRecord = hInfo.RecordIndex;
propertyGridControl1.ShowEditor();
}
}
}

Telerik RadGrid Pdf Export not working correctly

This code is being run when a button is clicked on my page:
protected void btnExportToPdfButton_click(object sender, EventArgs e)
{
this.ProjectListGrid.ExportSettings.ExportOnlyData = true;
this.ProjectListGrid.ExportSettings.Pdf.PageLeftMargin = Unit.Parse(".2in");
this.ProjectListGrid.ExportSettings.Pdf.PageRightMargin = Unit.Parse(".2in");
ApplyStylesToPdfExport(this.ProjectListGrid.MasterTableView);
this.ProjectListGrid.MasterTableView.ExportToPdf();
}
public void ApplyStylesToPdfExport(GridTableView tableView)
{
// Get access to the header in the grid
GridItem headerItem = tableView.GetItems(GridItemType.Header)[0];
// Apply CSS Styles to the header
headerItem.Style["font-size"] = "8pt";
headerItem.Style["background-color"] = "#777";
headerItem.Style["color"] = "white";
// Apply CSS Styles to each cell in the header
foreach (TableCell cell in headerItem.Cells)
{
cell.Style["color"] = "red";
}
}
The pdf exports, just with no custom styles applied at all.
I have absolutely no idea what I am doing wrong.
For some reason, the control seems to rebind itself and thus it wipes out your inline styles. Possible cause for this behavior is that you set ExportSettings.IgnorePaging to true in your markup. If this is not the case, and if you still have this problem, post your code here so that I can examine it.

apply CSS dynamically in asp.net 2.0

I have a scrolling div with Three linkbuttons and three differents divs. I need to apply CSS to active linkbutton as soon as button is clicked.The codes used by me are:
protected void btnNetwork_Click(object sender, EventArgs e)
{
this.btnForecast.CssClass = "li_1";
this.btnBlog.CssClass = "li_2";
this.btnNetwork.CssClass = "li_3_active";
this.btnNetwork.ForeColor = System.Drawing.Color.White;
lblMsg.Visible = false;
BindGW("-----------------------------------");
Forecast.Visible = false;
Blog.Visible = false;
Network.Visible = true;
}
Thanks & Regards,
Khushi
Instead of using server side event use client side javascript event. Try:
$get('btnId').setAttribute("class", "some_class_name");
You will not be able to dynamically change the CSS properties of elements by using post-back, which refreshes the page. Javascript must be used if you want to the change to happen immediately.
Simple example:
take one button and one label
create one stylesheet and add class style1 as:
body
{
}
.style1
{
color: #000080;
}
write this simple code in button click event
protected void Button1_Click(object sender, EventArgs e)
{
this.Label1.CssClass = "style1";
}

Resources