Devexpress GridView in Searchloookupedit use of - c#

As shown in the picture below, the product I am looking for from the SearchLookupEdit object I added on Gridview
I want to add them to the related columns on Gridview.
Despite my research I have not found or used incorrect search words. I did not get it.
When SearchLookupEdit is selected, I want to insert the column named CARPAN in the Çarpan column on the Gridview.
The codes I use in the SearchLookupEdit object
DataTable Veri = new DataTable();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["STOK"].ConnectionString);
conn.Open();
SqlDataAdapter __Da = new SqlDataAdapter("select ID,AD,CARPAN from STOK_BIRIM order by ID desc", conn);
__Da.Fill(Veri);
repositoryItemSearchLookUpEdit1.DataSource = Veri;
repositoryItemSearchLookUpEdit1.DisplayMember = "AD";
repositoryItemSearchLookUpEdit1.ValueMember = "ID";
repositoryItemSearchLookUpEdit1View.Columns.Clear();
repositoryItemSearchLookUpEdit1View.Columns.AddVisible("AD", "BİRİM ADI");
repositoryItemSearchLookUpEdit1View.Columns.AddVisible("CARPAN", "CARPAN");
repositoryItemSearchLookUpEdit1View.Columns["CARPAN"].Visible = false;
conn.Close();

Related

How to hide unnecessary columns in the GridControl?

Winform has 2 grids. I display related tables from the SQL Server database to them.
Here is the code:
string connectionString = ConfigurationManager.ConnectionStrings["connectionSIPiT"].ConnectionString;
string command = "SELECT UserID, UserName,Login, idArm FROM Users";
string command2 = "SELECT id, name FROM arm";
sqlConnection = new SqlConnection(connectionString);
SqlDataAdapter adapter = new SqlDataAdapter(command2, sqlConnection);
SqlDataAdapter adapter1 = new SqlDataAdapter(command, sqlConnection);
DataSet dataset1 = new DataSet();
adapter.Fill(dataset1, "arm");
adapter1.Fill(dataset1, "Users");
DataColumn keyColumn = dataset1.Tables[0].Columns[0];
DataColumn foreignKeyColumn = dataset1.Tables[1].Columns[3];
dataset1.Relations.Add("armUsers", keyColumn, foreignKeyColumn);
bindingSource1.DataSource = dataset1;
bindingSource1.DataMember = "arm";
bindingSource2.DataSource = bindingSource1;
bindingSource2.DataMember = "armUsers";
gridControl1.DataSource = bindingSource1;
gridControl2.DataSource = bindingSource2;
Please help me figure out how to hide unnecessary columns in the GridControl. Such as Id) Can the DataTable be used? If possible an example
After you set the DataSource for both grids, you can set the Visible property for the Id column to false.
Assuming the DefaultView is a GridView, the following code should do the job.
(gridControl1.DefaultView as GridView).Columns["Id"].Visible = false;

Show only unique columns in repeater control using asp c#

I'm trying to bind repeater control from database. But i need to bind repeater with unique column.
eg.
Mumbai, Haryana, Goa, Haryana, Mumbai
to
Mumbai, Haryana, Goa
My code is given below.
SqlConnection con3 = new SqlConnection("myconnection");
string strcon = "select * from indiapincodes where statename =#statename";
cmd = new SqlCommand(strcon, con3);
da = new SqlDataAdapter(cmd);
cmd.Parameters.AddWithValue("#statename", erouting);
ds = new DataSet();
da.Fill(ds, "emp");
Repeater1.DataSource = ds;
Repeater1.DataBind();
con3.Close();
con3.Dispose();
Above code is working good but i want to know how to filter column with unique value and fill in repeater. Thanks in advance.
string strcon = "SELECT DISTINCT columnname from indiapincodes WHERE statename=#statename";

how can I display data in the desiered row of datagridview bounded with database

I am using datagridview as in pic
column named ID has combobox . and DGV bounded with database using Data Table .
working is as following :-
when I select value from combobox in row 1 , then it display data in corresponding rows(i.e row 1) .
Issue :-
When I select value from combobox in row 2 , it does not display data in row 2 ,but shows it data in row 1 (i.e replacing earlier data in row 1).
how I can display data in row 2 and similarly for all other rows keeping the data selected in previous rows safe .....
how combobox is getting filled :-
sqlCmd.Connection = con;
sqlCmd.CommandType = CommandType.Text;
sqlCmd.CommandText = "SELECT id FROM dgvdata";
System.Data.SqlClient.SqlDataAdapter sqlDataAdap = new System.Data.SqlClient.SqlDataAdapter(sqlCmd);
DataTable dtRecord = new DataTable();
sqlDataAdap.Fill(dtRecord);
comboBox1.DataSource = dtRecord;
comboBox1.ValueMember = "id";
con.Close();
how datagridview filled on selection on combobox :-
con.Open();
string sql = "select time,PARTY_NAME , DATE from dgvdata where id ='" + comboBox1.Text + "'";
System.Data.SqlClient.SqlDataAdapter dataadapter = new System.Data.SqlClient.SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
dataadapter.Fill(dt);
dataGridView1.DataSource = dt;
con.close();
thanks in advance..

Put "ALL" on ComboBox[0] so that we filter it. NOTE: ComboBox has data from DB

For example, I have a Combo box with these contents coming from the database using SqlCommand, SqlDataAdapter and DataTable:
Japan
UK
USA
Philippines
Now, I want to add another choices. It should look like this:
----ALL----
Japan
UK
USA
Philippines
If I chose Japan, it will filter and show all the landmarks in the country like Mt. Fuji, Tokyo Tower.
If I chose UK, it will filter and show Big Ben, Westminster, Olympic Stadium.
If I chose USA, it will show fat people, Kim Kardashian.
IF I CHOSE ----ALL----, IT WILL SHOW ALL THE LANDMARKS FROM ALL COUNTRIES.
How do I do this? I'm using C# & SQL Server.
EDIT:
This is how I fill a combo box.
_con.Open();
SqlCommand _viewLandmarks = new SqlCommand("dbo.SelectDevices_AddingForm", _con);
_viewDevices.CommandType = CommandType.StoredProcedure;
_viewDevices.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(_viewLandmarks);
DataTable dTable = new DataTable("LANDMARK");
da.Fill(dTable);
comboModel.DataSource = dTable;
comboModel.DisplayMember = "Landmark";
comboModel.ValueMember = "LandmarkID";
_con.Close();
As said in comments it is just a matter to add a fake record in your returned datatable
_con.Open();
SqlCommand _viewLandmarks = new SqlCommand("dbo.SelectDevices_AddingForm", _con);
_viewDevices.CommandType = CommandType.StoredProcedure;
_viewDevices.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(_viewLandmarks);
DataTable dTable = new DataTable("LANDMARK");
da.Fill(dTable);
DataRow fakeRow = dTable.NewRow();
fakeRow["Landmark"] = "(ALL)";
fakeRow["LandmarkID"] = -1;
dTable.Rows.Add(fakeRow);
comboModel.DataSource = dTable;
comboModel.DisplayMember = "Landmark";
comboModel.ValueMember = "LandmarkID";
_con.Close();
I have added the open/close parenthesys around ALL to to force the new added row to the beginning of your datatable (assuming that it is sorted by Landmark).
Notice also that this approach assumes also that your fields are all NULLABLE. If one or more fields doesn't allow null values you need to set an appropriate value before adding the fakeRow to the Datatale rows collection
Just add a row in your datatable before binding and set the value to All.
Below is a example of binding the combo box
private void BindCombo()
{
DataTable dataTable = GetDataTable();
DataRow row = dataTable.NewRow();
row["Value"] = "0";
row["Name"] = "All";
dataTable.Rows.InsertAt(row, 0);
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "Value";
comboBox1.DataSource = dataTable;
}

How can I add extra column in datagridview when I fetch data from database

In my database I have 4 column. I fetch this database value in a datagridview. But I want to add two columns in datagridview. So, I want to make a datagridview with 6 columns. Within this 6 columns 4 columns will filled by database value. How can I do this?
OleDbConnection con = new OleDbConnection("CONNECTION STRING");
con.Open();
DataTable dtusers = new DataTable();
OleDbCommand cmd = new OleDbCommand("Select Code,Description,Qnty,Rate from PurchaseTable'", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dtusers);
dataGridView1.DataSource = dtusers;
dataGridView1.Columns[0].Name = "Code ";
dataGridView1.Columns[1].Name = "Description";
dataGridView1.Columns[2].Name = "Qnty";
dataGridView1.Columns[3].Name = "Rate";
con.Close();
Here are 4 columns. Code,Description,Qnty,Rate. I want to add two more columns in this datagridview. Amount and Narration. But Amount and Narration columns are not present in PurchaseTable.How can I do this?
If you want blank columns then create them and insert. If the data is in the database then add a join to your query to retrieve the data.
Adding blank columns
DataGridView dgv = new DataGridView();
dgv.DataSource = dtusers;
DataGridViewColumn amount = new DataGridViewColumn();
amount.HeaderText = "Amount";
amount.Name = "Amount";
dgv.Columns.Insert(0, amount);
DataGridViewColumn narration = new DataGridViewColumn();
narration.HeaderText = "Narration";
narration.Name = "Narration";
dgv.Columns.Insert(0, narration);
Assumed that you already have dtusers ..
Do Column adding to dtuser .. http://msdn.microsoft.com/en-us/library/hfx3s9wd.aspx
Do looping for all rows in your table to fill your new column
Assign the table as dgv datasource .. dataGridView1.DataSource = dtusers;
Because your column names are hardcoded, I think you can create a predefined columns in your datagridview through designer(Click datagridview -> choose Edit Columns).
Create all 6 columns you want. On the first four set DataPropertyName to name of the column from your query. Last two leave empty.
And remember set datagridview.AutoGeneratedColumns = false; before you binding data to datagridview...(somewhere in form_Load handler)
After this your code will be:
using (OleDbConnection con = new OleDbConnection("CONNECTION STRING"))
{
con.Open();
DataTable dtusers = new DataTable();
using(OleDbCommand cmd = new OleDbCommand("Select Code,Description,Qnty,Rate from PurchaseTable'", con))
{
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dtusers);
dataGridView1.DataSource = dtusers;
}
con.Close();
}

Categories