[View][1]I'm creating a bounded radgrid, i was trying to add bounded combobox to rad grid, but column is showing.combobox are't show.
You can find various samples for using RadGrid in combination with combo/dropdownlist provided in this post.
First: you need to be a little more explicit in your question or problem.
Maybe adding a little code or images will help us understand more.
From what i understand, you have a radgridview and you want a specific column to have a combobox as a type.
You can do something like this:
//define a GridViewMultiComboBoxColumn
GridViewMultiComboBoxColumn column = new GridViewMultiComboBoxColumn();
column.Name = "Your column name";
column.HeaderText = "The header text you want to have";
column.FieldName = "Field name, maybe you have a class read from a db";
column.DataSource = ds; //here you need to define your datasource for your combobox
column.ValueMember = "Value"; //depends on what you receive from datasource
column.DisplayMember = "Value"; //depends on what you receive from datasource
//add the column to your radgridview
gridView.MasterTemplate.Columns.Add(column);
Related
Background
I'm trying to set a column on my DGV up as a combobox. I've added all the columns to the gridview in the designer so all that is left is to bind them to the dataset.
The datatype of the Status column is varchar.
Question
However i keep getting a very unhelpful error message at run time. Am i doing something wrong?
DataGridViewComboBox Value is not valid.
The above error happens when setting the datasource of the dgv.
dataGridView1.DataSource = JoblistDataSet.Tables["Joblist"];
My Code
DataGridViewComboBoxColumn Column = (DataGridViewComboBoxColumn)dataGridView1.Columns["Status"];
Column.DataPropertyName = "Status";
DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)dataGridView1.Rows[0].Cells["Status"];
cbCell.Items.Add("New");
cbCell.Items.Add("Hold");
cbCell.Items.Add("Remove");
dataGridView1.DataSource = JoblistDataSet.Tables["Joblist"];
I think the problem is that you are populating DataGridViewComboBoxCell.Items for row index 0 instead of DataGridViewComboBoxColumn.Items which applies for all rows (hope you noticed Cell vs Column).
Use something like this instead
var statusColumn = (DataGridViewComboBoxColumn)dataGridView1.Columns["Status"];
statusColumn.DataPropertyName = "Status";
statusColumn.Items.Add("New");
statusColumn.Items.Add("Hold");
statusColumn.Items.Add("Remove");
// ...
I want to learn Telerik. But I am too newbee.
I have a table named "makale" and it has 7 column named, "no", "ad", "yazar", "kunye", "ders", "olusturma", "guncelleme"
I created a Link to SQL class and I managed to get data like this:
LinqtoSQLDataContext oc = new LinqtoSQLDataContext ();
var all = oc.makales;
Now I want to fetch this table to Telerik Radgridview. When I use Gridview1.DataSource = all; code, it fetches all columns. But I want to fetch only "ad", "yazar", "kunye" and "ders" columns. And I want to change gridview columns' text like "AD", "YAZAR", "KÜNYE", "ŞİŞKO". But when I use Gridview1.DataSource = all; code, gridview columns' text are same as table's columns' name. And I want to set columns' width too.
Could you help me, how can I do this?
In your case RadGridView generating columns automatically based on the DataSource (Gridview1.DataSource = all;)
My advise generate columns by yourself. Telerik. Generating columns
Set MyRadGridView.AutoGenerateColumns = false;
Then create column
GridViewTextBoxColumn yazarColumn = new GridViewTextBoxColumn("UniqueNameYazarColumn");
yazarColumn.Name = "UniqueNameYazarColumn";
textBoxColumn.HeaderText = "Your header";
textBoxColumn.FieldName = "yazar"; //Field is name of the bounded property of source
//add column to the grid
MyRadGridView.Columns.Add(yazarColumn);
Telerik have good enough documentation and basic examples for Winforms controls
Telerik UI Winforms.. GridView
To solve this problems you have 2 ways to do it.
First you can do the "Gridview1.DataSource = all" and then edit the columns that it has generated, or you can previously set up all columns you want to see and then use the Datasource.
The first one is the easy way to begin with.
After you link using "Gridview1.DataSource = all"
you said that all columns are "no", "ad", "yazar", "kunye", "ders", "olusturma", "guncelleme" but only "ad", "yazar", "kunye" and "ders" should appear.
You need to work all the columns like this >>>>
if you want to edit for the names use this:
this.Gridview1.Columns["put_the_name_of_the_column_here"].HeaderText = "Put the name you want to appear on the screen top of the grid here";
this.Gridview1.Columns["put_the_name_of_the_column_here"].IsVisible = false;
if you want the columns not to appear:
this.Gridview1.Columns["put_the_name_of_the_column_here"].IsVisible = false;
Example:
this.Gridview1.Columns["no"].IsVisible = false;
this.Gridview1.Columns["ad"].HeaderText = "AD";
this.Gridview1.Columns["ad"].IsVisible = true;
this.Gridview1.Columns["yazar"].HeaderText = "YAZAR";
this.Gridview1.Columns["yazar"].IsVisible = true;
and so on.....
I´ve working with Telerik´s for Winforms for 5 years now.... I hope I could help...
See ya..
I'm a SQL DBA with low skill level in VS C# and Winforms. I've been struggling with adding a combo box to a DataGridView column for several days and have given up. I have a datatable dt1 and datagridview dg1. dg1.Datasource = dt1; dt1 is a member of dataset ds1. I am providing combo items from an array.
I have tried autogeneration true and false.
If autogeneration=true I get two columns of the same name with 1 combo box and it's in the wrong column position and I get correct data from dt1
If false and I programmatically define columns for dg1, I don't get any data from dt1.
What should my code look like and what possible bindings or properties am I missing so that I add a combo box for 'GRADE' in the 4th column position and dg1 populates from dt1 and combo from array.
Totally frustrated after reading dozens of blogs and trying things for several days. Please help.
private DataGridViewComboBoxColumn CreateComboBox()
{
DataGridViewComboBoxColumn combo = new DataGridViewComboBoxColumn();
{
combo.Name = "comboColumn";
combo.HeaderText = "Grade";
ArrayList drl = new ArrayList();
drl.Add("GS1");
drl.Add("GS2");
drl.Add("WG1");
drl.Add("WG2");
combo.Items.AddRange(drl.ToArray());
combo.DataSource = drl;
//combo.ValueMember = "EmployeeID";
//combo.DisplayMember = "Grade";
//combo.DataPropertyName = "Grade";
}
return combo;
}
public Employee()
{
InitializeComponent();
WindowState = FormWindowState.Maximized;
Ds1 = new DataSet("ds1");
Dt1 = new DataTable("dt1");
ds1.Tables.Add(dt1);
dt1.Columns.Add("EmployeeID");
dt1.Columns.Add("FirstName");
dt1.Columns.Add("LastName");
dt1.Columns.Add("Grade");
dt1.Columns.Add("DOB");
//initialize datagridview
Dg1.AutoGenerateColumns = true;
//dg1.Columns.Add("column4", " EmployeeID ");
// dg1.Columns.Add("column4", " FirstName ");
// dg1.Columns.Add("column4", " LastName ");
Dg1.Columns.Add(CreateComboBox());
// dg1.Columns.Add("column5", " DOB ");
Dg1.DataSource = dt1;
}
Resolved: After several days hunting and trying, I tried a solution I didn't think would work because it mentioned an unbound column and appeared to require a SQL or some other connection make it a bound column. Turns out it isn't necessary to bind the columns. Here is what you do.
1.Open your Form designer an place Focus on your DataGridView and select properties.
2.Scroll down to the Columns collection (mine was at the bottom under Misc.) and expand the collection.
3.Add Column name and if binding to DataTable set the DataPropertyName to the dt column. In my case I set both the same.
Also there is a drop down to choose the ColumnType
4.Add your ComboBox column. This has a few more settings. You should look through all of them but I was interested in Items &
HeaderText only. I set HeaderText the same as ColumnName &
DataPropertyName. I then opened the Items and added my list.
There is also a DataSource. I presume that is for populating your
ComboBox from a database, service, or sharepoint but I'm not doing
that.
5.That's it.
In your .cs code file you need to insert two lines of code. I placed mine at the top of the form where I declare datatables I need available to all methods.
<yourdatagridview>.AutoGenerateColumns = false;
<yourdatagridview>.DataSource = <yourdatatable>;
I have a DataGridView with the columns added manually, for example:
DataGridViewLinkColumn col = new DataGridViewLinkColumn() { HeaderText = "", DataPropertyName = "PropValue", ReadOnly = true };
this.dataGridResults.Columns.Add(col);
The datasource is a stored procedure which returns a list with "PropValue" and "PropText" among others.
My problem is that this DataGridViewLinkColumn must show the text from "PropText" and have its value bound to "PropValue". However it seems that DataPropertyName is not that flexible, it only binds to one data type returned from the datsource.
If the problem explanation isn't clear please let me know.
Ideas?
Thank you in advance
You can use this:
DataGridViewLinkColumn links = new DataGridViewLinkColumn();
links.HeaderText = "Hello";
links.UseColumnTextForLinkValue = true;
links.Text="http://microsoft.com";
links.ActiveLinkColor = Color.White;
links.LinkBehavior = LinkBehavior.SystemDefault;
links.LinkColor = Color.Blue;
links.TrackVisitedState = true;
links.VisitedLinkColor = Color.YellowGreen;
dataGridView.Columns.Add(links);
I got it from this link:
How to add DataGridViewLinkColumn property to dynamically generated columns in DataGridView?
I ended up using two separate columns, with one invisible that contains the other value i needed. binding both columns from the dataset into th same datagridview column is not possible.
Using c# .net 2.0 , I want to bind a textbox to a specific row of my table. In Example :
Table Person
ID NAME PRENOM SPECIAL_CATEGORY
1 BOB BOB mex
2 AL AL tot
3 PO PO pap
I want to bind my textbox on the field name where the row contains special_categeory = 'tot'.
Is it possible? or I need to create a Datarow for this row and binding it.
Assuming you're talking about Winforms and you have your data source as a component on your form already, this is fairly simple.
Drag a new BindingSource onto your form and set its data source to be whatever your existing data source is. You can then specify a filtering expression in the new BindingSource's Filter property in the designer. Bind your TextBox to your new BindingSource and you're all set.
Doing this manually (without the designer) is only marginally more complicated.
BindingSource newSource = new BindingSource();
newSource.DataSource = yourExistingDataSource;
newSource.Filter = "special_categeory = 'tot'";
textBox.DataBindings.Add("Text", newSource, "DataMember");
You should be able to bind via...
myNameTextBox.DataBindings.Add( "Text", MyTable, "NAME" );
myPrenomTextBox.DataBindings.Add( "Text", MyTable, "PRENOM" );
mySpecial_CategoryTextBox.DataBindings.Add( "Text", MyTable, "SPECIAL_CATEGORY" );
I actually have a framework that scrolls through all controls, and if they match a column name in a given table, they immediately bind themselves like above.
Then, when you scroll the grid, it should also refresh the individual text controls in your form too.
If there is some binding that needs to be done, you can follow this pattern:
DataView dv = new DataView(MyTable);
dv.RowFilter = "SPECIAL_CATEGORY = 'tot'";
GridView1.DataSource = dv;
GridView1.DataBind();
But I don't think you bind to a TextBox? You can set the Text property like:
foreach(DataRow dr in MyTable.Rows)
{
if (dr["SPECIAL_CATEGORY"] != DBNull.Value &&
dr["SPECIAL_CATEGORY"].ToString() == "tot")
{
myTextBox.Text = dr["NAME"].ToString()
break;
}
}
I'm going to assume it's Winforms and this is how you can do it:
myTable.DefaultView.RowFilter = "SPECIAL_CATEGORY = 'tot'";
this.textBox1.DataBindings.Add("Text",myTable.DefaultView,"Name");