{
LoadDataTable = SqlHelper.GetTable(LoadProcedureSelectName, Args);
}
catch (Exception e)
{
CreateSelectProcedure(LoadProcedureSelectName);
}
LoadData(LoadDataTable);
9 Answers, 1 is accepted
To enable binding using UniqueName property you need to make the following modification:
Original code:
GridViewColumn col =
new
GridViewColumn();
Modified Code:
Telerik.Windows.Controls.GridViewColumn col =
new
Telerik.Windows.Controls.GridViewDataColumn();
Hope this helps.
Best wishes,
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Attached you will find a sample project which uses your code to displays the Grid View data.
Additionally you may consider using the column property DataMemberBinding which provides more flexible way to bind the data using Bindings. (See the commented code in GenerateTextBoxWPF method).
Also you can look at option for auto generating columns and using AutoGeneratingColumn event to customize each column.If you have any more questions do not hesitate to contact us.
Best wishes,
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Can you provide additional information about datatable content?
About your concern that column types are hardcoded - you can take advantage of an ability in Gridview data column - it can automatically resolve property type and display the controls needed (e.g. for boolean properties - checkbox is displayed)
In addition you can enable AutogenerateColumn=true and attach to AutogeneratingColumn event to customize the column as needed.
Kind regards,Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
As I understand you need to design the grid in such a way that it will be able to visualize data without knowing its fields. In addition you will load saved data about grid columns current state.
I assume that there is some correlation between data that will be visualized and saved settings data (e.g. you keep saved settings about how the grid looks like when displaying Orders data - 5 columns, two invisible with specific width for each column; another set of settings which keeps track of how the grid will look like when displaying Costumers data - 10 columns, 5 visible with specific width).
Thus I have extended the example and have added comments how you can bind your grid with any data (two different data tables are used to illustrate the idea) and loads specific settings depending on data loaded. The grid view does not have any knowledge about contents of data displayed.
Please let know if this works for you.
Sincerely yours,
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
protected void LoadData() |
{ |
DataTable table = null; |
table = SqlHelper.GetTable(LoadProcedureSelectName, Args); |
dataGridView1.AutoGenerateColumns = false; |
dataGridView1.DataMember = null; |
dataGridView1.Columns.Clear(); |
if (dataGridView1.Columns.Count == 0) |
GenerateColumns(table); |
dataGridView1.ItemsSource = table.DefaultView; |
} |
protected void GenerateColumns(DataTable dataTable) |
{ |
dataGridView1.Columns.Clear(); |
//get the data for the column settings from the database |
DataTable columnTypes = SqlHelper.GetTable("base_Fields_SelectVisible", new string[] { "@UserID", Globals.UserID, "@TableName", _TableName }); |
foreach (DataRow dr in columnTypes.Rows) |
{ |
GenerateColumn(dr); |
} |
} |
private void GenerateColumn(DataRow dr) |
{ |
Telerik.Windows.Controls.GridViewDataColumn col = new Telerik.Windows.Controls.GridViewDataColumn(); |
col.Name = dr["FieldName"].ToString(); |
col.Header = dr["Caption"].ToString(); |
//col.DataMemberBinding = new Binding(dr["FieldID"].ToString()); |
col.UniqueName = dr["FieldID"].ToString(); |
col.IsReadOnly = true; |
col.Width = Convert.ToInt32(dr["width"].ToString()); |
dataGridView1.Columns.Add(col); |
if (dr["Visible"].ToString() == "1") |
{ |
dataGridView1.Columns[dataGridView1.Columns.Count - 1].IsVisible = true; |
} |
else |
{ |
dataGridView1.Columns[dataGridView1.Columns.Count - 1].IsVisible = false; |
} |
} |
Can you please check whether the application runs without any exceptions in the output window in debug mode?
If it is not, can you please provide that part of your project that uses GridView including database schema and SQLHelper class, so that I can modify it to work correctly.
Sincerely yours,
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.