BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
//Register the cell model -> Syncfusion.GridHelperClasses.Windows.dll RegisterCellModel.GridDataBoundCellType(this.gridDataBoundGrid1, CustomCellTypes.ButtonEdit); this.gridDataBoundGrid1.TableStyle.CellType = CustomCellTypes.ButtonEdit.ToString();
//show the buttons only on current cell editing. this.gridDataBoundGrid1.TableStyle.ShowButtons = Syncfusion.Windows.Forms.Grid.GridShowButtons.ShowCurrentCellEditing;
|
Query 1 after changing positions bottom is invisible but still working |
To enable the button click only on current cell in edit mode, it can be achieved by using the below code snippet, Code Snippet: void gridDataBoundGrid1_CellButtonClicked(object sender, Syncfusion.Windows.Forms.Grid.GridCellButtonClickedEventArgs e) { //Disable the button click if (this.gridDataBoundGrid1.Binder.CurrentRowIndex != e.RowIndex) return; MessageBox.Show(this.gridDataBoundGrid1[e.RowIndex, e.ColIndex].Text); } |
Query 2 How to serialize the contents of the grid to xml file. |
If you want to save the settings of the file to an xml document. You can save it by using the SaveSoap method. Please refer the below code snippet, Code snippet: //To save the grid settings as the xml data. this.gridDataBoundGrid1.Model.SaveSoap("Soap.xml"); We would also like to suggest you to refer the below KnowledgeBase document. Which may help you to manually configure the xml document. KB Link: http://www.syncfusion.com/kb/723/is-there-an-effective-way-to-persist-the-state-of-expanded-collapsed-row-when-we-re-bind-the |
I created tables:
Create Table [UserTable] (ID int, [UserObject] xml)
How to save a file Soap.xml to a table UserTable
UserTable
public DataTable CreateDataTable()
{
DataTable dt = new DataTable("Xml-Data");
dt.Columns.Add(new DataColumn("id", typeof(int)));
dt.Columns.Add(new DataColumn("xml", typeof(object)));
return dt;
}
//Serialization using Soap Formatter
FileDialog dlg = new SaveFileDialog();
dlg.Filter = "Soap files (*.soap)|*.soap|All files (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
//Save the grid model object to a stream in SOAP format
this.gridDataBoundGrid1.Model.SaveSoap(dlg.FileName);
XmlTable = this.CreateDataTable();
DataRow row = XmlTable.NewRow();
row[0] = 1;
row[1] = dlg.FileName;//Add the xml file to the data table
XmlTable.Rows.Add(row);
}
//To load the xml file from the datatable
this.gridDataBoundGrid1.Model = GridDataBoundGridModel.LoadSoap(this.XmlTable.Rows[0].ItemArray[1].ToString());
Note:
Since the GridDataBoundGrid is populated with a bound source, the values of the cells will not be stored in the xml file. If you want to get including values of the cells, please refer to the below dashboard sample, it will shows how to serialize and de-serialize the contents of the grid.
Dashboard sample:
<InstalledLocation>\Syncfusion\EssentialStudio\<VersionNo>\Windows\GridDataBound.Windows\Samples\Serialization\Serialize Grid Data Bound Grid Demo\CS
Regards,
Adhi
Now I have:
......................................................................................
public void initializegrid_01()
{
if (File.Exists("MySizes.bin"))
{
try
{
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MySizes.bin", FileMode.Open, FileAccess.Read, FileShare.None);
try
{
this.gridDataBoundGrid1.BeginUpdate();
//handle the mappingnames
GridBoundColumnsCollection col =
(GridBoundColumnsCollection)this.gridDataBoundGrid1.GridBoundColumns.Clone();
if (col.Count == 0)
col = this.gridDataBoundGrid1.Binder.InternalColumns;
string[] a = (string[])formatter.Deserialize(stream);
this.gridDataBoundGrid1.GridBoundColumns.Clear();
foreach (string s in a)
{
GridBoundColumn c = col[s];
this.gridDataBoundGrid1.GridBoundColumns.Add(c);
}
this.gridDataBoundGrid1.Model.ColWidths.Dictionary =
(Syncfusion.Windows.Forms.Grid.GridRowColSizeDictionary)formatter.Deserialize(stream);
}
finally
{
this.gridDataBoundGrid1.EndUpdate();
this.gridDataBoundGrid1.Refresh();
stream.Close();
}
}
catch (Exception ex)
{ }
}
}
void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
//Serialize out the row heights & column widths
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MySizes.bin", FileMode.Create, FileAccess.Write, FileShare.None);
//Handle the mapping names
GridBoundColumnsCollection col = (GridBoundColumnsCollection)this.gridDataBoundGrid1.GridBoundColumns;
if (col.Count == 0)
col = this.gridDataBoundGrid1.Binder.InternalColumns;
int nCols = col.Count;
string[] a = new string[nCols];
int i = 0;
foreach (GridBoundColumn c in col)
a[i++] = c.MappingName;
formatter.Serialize(stream, a);
formatter.Serialize(stream, this.gridDataBoundGrid1.Model.ColWidths.Dictionary);
stream.Close();
}
catch (Exception ex)
{ }
}
......................................................................................
MySizes.bin
)MySizes.bin
- the settings stored in the SQL databaseTable [UserTable] (ID int, [UserObject] xml)
ID = id Form (Form1= 1,
Form2= 2,
etc.) - UserObject = (xml format strem setings Form
gridDataBoundGrid1
parameters , properties --
MySizes.bin
)