set value in BaseFieldControl or RichTextField - c#

I want programmatical set value in my own field type. So I override method FieldRenderingControl (this is call when click into element in sharepoint list).
my code:
public override Microsoft.SharePoint.WebControls.BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl fakeFieldControl = base.FieldRenderingControl;
RichTextField rtf = new RichTextField();
rtf.ID = "MultilineRichText";
rtf.ListId = fakeFieldControl.ListId;// list.ID;
rtf.ItemId = fakeFieldControl.ItemId;// item.ID;
rtf.FieldName = "MultilineRichText";
rtf.ControlMode = SPControlMode.Display;
rtf.Text = "test rich text";
rtf.Value = "test rich text value";
rtf.ItemFieldValue = "item field value";
rtf.ListItemFieldValue = "list item field value";
return rtf;
the result: contol mode is always in display mode, that work fine. But the column value is always empty.
Any help? I do not have any idea!

If I remember correctly, you have to set the value BEFORE setting the ControlMode = SPControlMode.Display.
Edit: I just saw that's an old post... hope you had find an answer :)

Related

PDF Checkbox Error : Value cannot be null. Parameter name: value

I am trying to check a checkbox in PDFform using PDFsharp. I am using below code
PdfCheckBoxField chkbox = (PdfCheckBoxField)(pdf.AcroForm.Fields["chkbox"]);
chk.ReadOnly = false;
chk.Checked = true;
chk.ReadOnly = true;
I am getting below error on line chk.Checked = true;
ArgumentNullException was unhandled
Value cannot be null.
Parameter name: value
You are reading the object into 'chkbox', but setting 'chk':
PdfCheckBoxField chkbox = (PdfCheckBoxField)(pdf.AcroForm.Fields["chkbox"]);
chkbox.ReadOnly = false;
chkbox.Checked = true;
chkbox.ReadOnly = true;
I'm not sure why it isn't failing on the first line.
This little gem came from looking at the PDFSharp source code. This is how to set the value for checkboxes with the same name. I can't tell exactly if this was the original problem posted, but based on the error, and my own frustration, I came up with this solution.
//how to handle checking multiple checkboxes with same name
var ck = form.Fields["chkbox"];
if (ck.HasKids)
{
foreach (var item in ck.Fields.Elements.Items) {
//assumes you want to "check" the checkbox. Use "/Off" if you want to uncheck.
//"/Yes" is defined in your pdf document as the checked value. May vary depending on original pdf creator.
((PdfDictionary)(((PdfReference)(item)).Value)).Elements.SetName(PdfAcroField.Keys.V, "/Yes");
((PdfDictionary)(((PdfReference)(item)).Value)).Elements.SetName(PdfAnnotation.Keys.AS, "/Yes");
}
}
else {
((PdfCheckBoxField)(form.Fields["chkbox"])).Checked = true;
}
I encountered a similar problem.
The error was in the created form checkbox field.
I had different value set as export value. Use default value.

How to provide images for checkbox in an unthemed DevExpress GridView?

I turned DevExpress Themes off for DevExpress GridView, does anybody know how to provide images for checked unchecked?
var grid = Html.DevExpress().GridView( settings => {
settings.EnableTheming = false;
settings.Columns.Add("isGrant", "Grant", MVCxGridViewColumnType.CheckBox);
}
When theming is on, I get nice check boxes in the grid, when it is off, there is no indication of any check marks, when "isGrant" is true. Does anybody know how to show an image when true, and a different image when false when themes are off?
Solved my own problem ... what I did was modify the VIEW and included this property:
public string GrantCheck {
get {
return isGrant ? "<img src='/Theme/css/images/checkmark.png'>" : " ";
}
}
Then in the gridview added a column with:
settings.Columns.Add(column => {
column.ColumnType = MVCxGridViewColumnType.TextBox;
column.FieldName = "GrantCheck";
column.Caption = "Grant";
column.PropertiesEdit.EncodeHtml = false;
column.CellStyle.CssClass = "dxcheckbox";
});
This way I get a nice check box. The css class is defined as:
.dxcheckbox { text-align: center;}
Cheers.

Updating NodeView cells in GTK#

How to make a NodeView cell retain the entered value after text's been entered through keyboard and the Edited event fired?
Whenever I enter some text into the cell and try to confirm that change, the old value that was there before my editing comes back.
The property of the subclass that should hold the value of a node never gets updated with the new value.
How do I get the text entered into a NodeView cell in the first place?
The trick is to use the Path property of the Gtk.EditedArgs argument passed to your event handler to get the correct node from the store and modify (you're responsible to propagate the change from the UI to your model). A small, complete example follows.
Given the following Gtk.TreeNode implementation:
[Gtk.TreeNode]
public class MyTreeNode : Gtk.TreeNode
{
public MyTreeNode(string text)
{
Text = text;
}
[Gtk.TreeNodeValue(Column=0)]
public string Text;
}
it is easy to change the Text property as follows:
Gtk.NodeStore store = new Gtk.NodeStore(typeof(MyTreeNode));
store.AddNode(new MyTreeNode("The Beatles"));
store.AddNode(new MyTreeNode("Peter Gabriel"));
store.AddNode(new MyTreeNode("U2"));
Gtk.CellRendererText editableCell = new Gtk.CellRendererText();
Gtk.NodeView view = new Gtk.NodeView(store);
view.AppendColumn ("Artist", editableCell, "text", 0);
view.ShowAll();
editableCell.Editable = true;
editableCell.Edited += (object o, Gtk.EditedArgs args) => {
var node = store.GetNode(new Gtk.TreePath(args.Path)) as MyTreeNode;
node.Text = args.NewText;
};
Note:
the use of args.Path to get the correct MyTreeNode from the store; and
the cast of the result to MyTreeNode to be able to access the Text property.

Can't display linklabel text in a datagridviewlinkcolumn

I have a little but pretty annoying problem:
I have created a datagridview and bound it to a datasource.
Then now I want to add a column which will display links for the user to click.
In order to do that i added a datagridviewlinkcolumn. For each rows of the datagrid I set the value of the cell in that column to the text i want to be displayed. But it shows nothing. All the datagridlinkcolumn is filled with "blank text".
Here is my code:
DataGridViewLinkColumn dgvColDeletion = new DataGridViewLinkColumn();
dgvColDeletion.Name = "Deletion";
dgvColDeletion.HeaderText = "";
dgvColDeletion.ReadOnly = false;
dgvTrainings.Columns.Add(dgvColDeletion);
foreach (DataGridViewRow row in dgvTrainings.Rows)
{
row.Cells["Deletion"].Value = "Delete";
}
dgvColDeletion.Update();
dgvTrainings.Update();
I also tried with setting directly linklabels or datagridviwlinkcells, but the problem still remains.
I cant get any clue why this isn't working.
Any help will be very much appreciated, thanks.
To display the same link text for every cell, set the UseColumnTextForLinkValue property to true and set the Text property to the desired link text.
DataGridViewLinkColumn dgvColDeletion = new DataGridViewLinkColumn();
dgvColDeletion.UseColumnTextForLinkValue = true;
dgvColDeletion.Text = "Delete";
Try this. I hope this will helps to you.
DataGridViewLinkColumn dgvColDeletion = new DataGridViewLinkColumn();
dgvColDeletion.UseColumnTextForLinkValue = true;<br/>
dgvColDeletion.Text = "Delete";<br/>
dgvColDeletion.ActiveLinkColor = Color.White;<br/>
dgvColDeletion.LinkBehavior = LinkBehavior.SystemDefault;<br/>
dgvColDeletion.LinkColor = Color.Blue;<br/>
dgvColDeletion.TrackVisitedState = true;<br/>
dgvColDeletion.VisitedLinkColor = Color.YellowGreen;<br/>
dgvColDeletion.Name = "Delete";<br/>
dgvColDeletion.HeaderText = "Delete";<br/>
if (grid_shared.Columns.Contains("Delete") == false)<br/>
{<br/>
dgvColDeletion.Columns.Add(lnkDelete);<br/>
dgvColDeletion.Columns["Delete"].Width = 40;<br/>
}<br/>
Happy coding..:)

Assignment Problem

my problem is that for some reason, a simple assignment isn't working.
the dataGridView is binded to DB and im trying to assign a value type string to a column of type string
enter code here //the initialization of the DataGridView
bindingSourceSchema.DataSource = null;
dgwSchema.Columns["colID"].DataPropertyName = "APP_ID";
dgwSchema.Columns["colName"].DataPropertyName = "DESCRIPTION";
dgwSchema.Columns["colTextbox"].DataPropertyName = "APP_ARGS";
dgwSchema.Columns["colTextbox"].HeaderText = "Parameters";
dgwSchema.Columns["colLink"].DataPropertyName = "APP_PATH";
dgwSchema.Columns["colLink"].HeaderText = "Path";
DataGridViewLinkColumn colLink = (DataGridViewLinkColumn)dgwSchema.Columns["colLink"];
colLink.UseColumnTextForLinkValue = true;
colLink.Text = "Edit";
bindingSourceSchema.DataSource = SchemaDB.GetGenericApps();//the assignment
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
dgwSchema.CurrentRow.Cells["colLink"].Value = openFileDialog.FileName;
// !! ?? dgwSchema.CurrentRow.Cells["colLink"].Value STAYS with parameter "Edit"
}
Thanks
Eyal
It could be a problem with where you are running this code. Is this in the PageLoad event? Make sure the grid is not being bound again after you do this. What does the debugger show you if you put a break point after the assignment?
The reason is following property is set to true.
colLink.UseColumnTextForLinkValue = true;
Set it to false. Then it will resolve your problem.

Categories