Showing posts with label datagrid. Show all posts
Showing posts with label datagrid. Show all posts

Sunday, March 11, 2012

Datagrids

Having populated my datagrid with the following code,

DA = New SqlCeDataAdapter(SqlceCmd)
MyData = New DataTable
DA.Fill(MyData)
MyData.Columns(0).ColumnName = "Task"
MyData.Columns(1).ColumnName = "Reported"

IncidentDtl.DataSource = MyData
IncidentDtl.Refresh()

I now want to change the size of the columns. Could someone please let me know how to manipulate the appearance of my grid as my grid IncidentDtl doesn't seem to have a Columns property only the Table does.

I would take this thread to one of the Visual Studio or Visual Basic (or even C#) forums. Many of these SQL Server folks don't have much experience with the inner workings of the DataGridView control.

The DataGridView has any number of properties like the AutoSizeColumnsMode that can automatically set the size of the columns based on the first row width, the displayed rows maximum width etc.

|||

What about:

Code Snippet

DataGridView dgw = new DataGridView();

dgw.Columns["SomeColumn"].Width = 100;

Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

Ah, that would be nice, but the Columns collection.Width property is read-only.

|||http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.width.aspx

DataGridViewColumn.Width Property

Gets or sets the current width of the column.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Jens K. Suessmeyer

http://www.sqlserver2005.de

Datagrids

Having populated my datagrid with the following code,

DA = New SqlCeDataAdapter(SqlceCmd)
MyData = New DataTable
DA.Fill(MyData)
MyData.Columns(0).ColumnName = "Task"
MyData.Columns(1).ColumnName = "Reported"

IncidentDtl.DataSource = MyData
IncidentDtl.Refresh()

I now want to change the size of the columns. Could someone please let me know how to manipulate the appearance of my grid as my grid IncidentDtl doesn't seem to have a Columns property only the Table does.

I would take this thread to one of the Visual Studio or Visual Basic (or even C#) forums. Many of these SQL Server folks don't have much experience with the inner workings of the DataGridView control.

The DataGridView has any number of properties like the AutoSizeColumnsMode that can automatically set the size of the columns based on the first row width, the displayed rows maximum width etc.

|||

What about:

Code Snippet

DataGridView dgw = new DataGridView();

dgw.Columns["SomeColumn"].Width = 100;

Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

Ah, that would be nice, but the Columns collection.Width property is read-only.

|||http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.width.aspx

DataGridViewColumn.Width Property

Gets or sets the current width of the column.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Jens K. Suessmeyer

http://www.sqlserver2005.de

Datagrid/Stored Procedure Issue

I have a developer that has databound datagrids as follows:
Datagrid.datasource= DataSet (yes, the compiler allows this)
The dataset is returned from stored procedures. Each of the sps return
a single recordset, but periodically we are seeing some
nondeterministic behavior where the code for the datasource above is
causing a runtime error. More than one recordset is being returned for
some reason.
Of course, the easiest way to fix this is to have the developer change
code to
Datagrid.datasource = DataSet.Table("Some Table or Index"),
but is there are anything that can be done from a SQL Server
standpoint, that will only return one recordset ?
TIAMJKulangara wrote:
> I have a developer that has databound datagrids as follows:
> Datagrid.datasource= DataSet (yes, the compiler allows this)
> The dataset is returned from stored procedures. Each of the sps return
> a single recordset, but periodically we are seeing some
> nondeterministic behavior where the code for the datasource above is
> causing a runtime error. More than one recordset is being returned for
> some reason.
> Of course, the easiest way to fix this is to have the developer change
> code to
> Datagrid.datasource = DataSet.Table("Some Table or Index"),
> but is there are anything that can be done from a SQL Server
> standpoint, that will only return one recordset ?
> TIA
The usual cause of extra resultsets is the lack of a "SET NOCOUNT ON"
statement in the stored procedure. This statement tells the query engine to
suppress the informational "x rows affected" messages that you see when
running queries in QA. These messages get sent as extra resultsets.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.|||Thanks Bob. I checked each of the sps called and they all have "SET
NOCOUNT ON". The strange thing here is that we don't always get an
error. Most of the time (90%) applications rnus without a problem.|||"MJKulangara" <RutgersDBA@.gmail.com> wrote in message
news:1140627492.706939.31610@.z14g2000cwz.googlegroups.com...
>I have a developer that has databound datagrids as follows:
> Datagrid.datasource= DataSet (yes, the compiler allows this)
> The dataset is returned from stored procedures. Each of the sps return
> a single recordset, but periodically we are seeing some
> nondeterministic behavior where the code for the datasource above is
> causing a runtime error. More than one recordset is being returned for
> some reason.
> Of course, the easiest way to fix this is to have the developer change
> code to
> Datagrid.datasource = DataSet.Table("Some Table or Index"),
> but is there are anything that can be done from a SQL Server
> standpoint, that will only return one recordset ?
> TIA
Run the stored procedure in Query Analyser (with parameters that cause the
error in your page).
Check if any messages are generated.
I had a similar problem with a stored procedure and found that it was
because of null values in aggregate functions.
Adding SET ANSI_WARNINGS OFF to the procedure solved the problem.
Note: make sure ANSI_WARNINGS is ON in QA options before doing the test.

DataGrid updation problem !

Hello all
i am trying to update the database with the DataSet (Updated from the DataGrid) but it is giving the error as
"Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information."
the code is as follows


public DataSet bindControlToGrid(DataSet dataSet)
{
SqlConnection objConn= null;
SqlCommand objComm = null;
try
{
objConn = new SqlConnection(@."User ID=sa;Password=sa;database=ExtraNet;server=EAGLES\EAGLES");

SqlDataAdapter objAdapter=new SqlDataAdapter();
objAdapter.SelectCommand= new SqlCommand("SELECT sUserID,sUserName FROM tblUser WHERE dUserDeActivated IS NULL ORDER BY sUserName,nUsrSerialNo",objConn);
SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(objAdapter);
objConn.Open();
DataSet objdataSet= new DataSet("ko");
string d = (dataSet.Tables[0].Rows[0].ItemArray.GetValue(0).ToString());

objAdapter.Fill(objdataSet);
objAdapter.Update(dataSet);
objAdapter.Dispose();
}
catch(Exception ex)
{
string s= ex.Message;
}
finally
{
//objComm.Dispose();
objConn.Close();
}
return dataSet;
}


kindly helpGot The Answere

sUserID was not declared as primary ker

Thanks all

Datagrid Delete

Hi I'm having a problem deleting rows from my datagrid. Basically I hit delete and a message box pops up and asks if Im sure I want to delete so I hit yes and then I get the following error -->Could not find stored procedure 'delete from SECTION_TBL where SECT_ID = @.SECT_ID'.

Is it my code thats wrong or is our test sql server that is the problem?

1<%@. Page Language="VB" EnableEventValidation="True" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>2<%@. import namespace="System" %>3<%@. import namespace="System.Data" %>4<%@. import namespace="System.Data.SqlClient" %>56<script language="VB" runat="server">78Dim sectionAs String9 Dim myconnectionAs SqlConnection10Dim mydaAs SqlDataAdapter11Dim dsAs DataSet1213Sub Page_Load(ByVal SourceAs Object,ByVal EAs EventArgs)14 BindData()15End Sub1617 Sub BindData()1819Dim strConnAs String ="server=fileserver; uid=xxx; pwd=xxx; database=NEW_CMS"20Dim sqlAs String ="Select * from SECTION_TBL"21 myconnection =New SqlConnection(strConn)22 myda =New SqlDataAdapter(sql, myconnection)23 ds =New DataSet24 myda.Fill(ds,"SECTION_TBL")25 sectList.DataSource = ds26 sectList.DataBind()2728End Sub2930 Private Sub sectList_ItemDataBound(ByVal senderAs Object,ByVal eAs DataGridItemEventArgs)Handles sectList.ItemDataBound3132Dim lAs LinkButton3334If e.Item.ItemType = ListItemType.ItemOr e.Item.ItemType = ListItemType.AlternatingItemThen35 l =CType(e.Item.Cells(0).FindControl("cmdDel"), LinkButton)36 l.Attributes.Add("onclick","return getconfirm();")37End If3839 End Sub4041 Sub sectList_DeleteCommand(ByVal sAs Object,ByVal eAs DataGridCommandEventArgs)4243Dim ConnectionStrAs String = ConfigurationManager.AppSettings("ConnStr")44Dim connAs SqlConnection45Dim cmdAs SqlCommand46Dim IdAs Integer4748 Id =CInt(e.Item.Cells(0).Text)49 conn =New SqlConnection("server=fileserver; uid=xxx; pwd=xxx; database=NEW_CMS")50 cmd =New SqlCommand("delete from SECTION_TBL where SECT_ID = @.SECT_ID", conn)51 cmd.CommandType = CommandType.StoredProcedure52 cmd.Parameters.Add("@.SECT_ID", SqlDbType.Int).Value = Id5354 cmd.Connection.Open()55 cmd.ExecuteNonQuery()56 cmd.Connection.Close()5758 DataBind()5960End Sub61626364</script>6566<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">6768<script language="javascript">6970function getconfirm()71{72if (confirm("Do you want to delete record?")==true)73return true;74else75return false;76}7778</script>7980<table cellpadding="2" cellspacing="2" width="760">81<tr>82<td>Sections</td>83</tr>84<tr>85<td>8687<asp:DataGrid OnDeleteCommand="sectList_DeleteCommand" ID="sectList" runat="server" DataKeyField="SECT_ID" AutoGenerateColumns="False">8889<Columns>9091<asp:BoundColumn DataField="SECT_ID" Visible="False" />9293<asp:HyperLinkColumn HeaderText="SECTION NAME" DataTextField="SECT_NAME" DataNavigateUrlField="SECT_ID" DataNavigateUrlFormatString="manageSection.aspx?SECT_ID={0}" />9495<asp:TemplateColumn>96<ItemTemplate>97<asp:LinkButton id="cmdDel" runat="server" Text="Delete" CommandName="Delete" CausesValidation="false" />98</ItemTemplate>99</asp:TemplateColumn>100101</Columns>102103</asp:DataGrid>104105</td>106</tr>107<tr>108<td></td>109</tr>110</table>111112</asp:Content>
 
Thanks in advance.

on line 51 you should use

CommandType.Text

|||

Brilliant - This works great

Thank you.

Datagrid dataset problem

For a datagrid dataset, I'm trying to take the amount of all the sales by a salesperson
in two days and create an alias for sum(saleamount) (which would become
allsales) to put the grand total in.

select
thedate, sum(saleamount) as allsales , salesperson, orderID
from
transactions
WHERE (thedate IN ('6/1/2005', '6/2/2005'))
GROUP BY Salesperson
HAVING SUM(allsales > 0)

I'm getting "invalid syntax near SUM (on the Having clause)" when trying to run this
query. And I know there is data in there meeting this criteria.
Thanks
chumley

Try moving the closign parenthesis behnd he column you are summing:
HAVING SUM(allsales) > 0

DataGrid DataSet DataAdaptor DataBase problem.

My dataset is not updating my database after the user modifies the datagrid.
I populate my data with the load sub below.
In the Save Sub (below), I have generated my DataSet 'dataSet11' from my
DataAdaptor 'SqlDataAdapter1' and the DataConnection 'SqlConnection1' and
they all seem to be connected correctly. But my data does not update.
the dataAdaptor is configured for Insert/Update/delete and the datagrid
datasource is DataSet11.TableName. Any ideas?
Private Sub Thresholds_Load(ByVal sender As....
Try
cn = New SqlClient.SqlConnection("user id=" & UserName.Text & ";password="
& Password.Text & ";database=" & Database.Text & ";server=" & Server.Text)
cn.Open()
cmdSelect.Connection = cn
Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("Select
* from MISRE_Threshold", cn)
Dim dsThreshold As DataSet = New DataSet
' fill dataset
da.Fill(dsThreshold, "MISRE_Threshold")
'Attach DataSet to DataGrid
dgThreshold.DataSource = dsThreshold.DefaultViewManager
Catch ex As Exception
MessageBox.Show("Error: Could not establish database connection")
End Try
Private Sub btnSave_Click(ByVal sender....
SqlDataAdapter1.Update(DataSet11)
EndSubThe DataAdapter InsertCommand/UpdateCommand/DeleteCommand properties need to
be set in order for the DataAdapter to execute the appropriate commands to
update your table. The SqlCommandBuilder can be used to generate the needed
commands (if you have a primary key) or you can create those the commands
yourself.
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)
Hope this helps.
Dan Guzman
SQL Server MVP
"marcmc" <marcmc@.discussions.microsoft.com> wrote in message
news:392099C1-6587-46B7-BD60-A20AD3C884AB@.microsoft.com...
> My dataset is not updating my database after the user modifies the
> datagrid.
> I populate my data with the load sub below.
> In the Save Sub (below), I have generated my DataSet 'dataSet11' from my
> DataAdaptor 'SqlDataAdapter1' and the DataConnection 'SqlConnection1' and
> they all seem to be connected correctly. But my data does not update.
> the dataAdaptor is configured for Insert/Update/delete and the datagrid
> datasource is DataSet11.TableName. Any ideas?
> Private Sub Thresholds_Load(ByVal sender As....
> Try
> cn = New SqlClient.SqlConnection("user id=" & UserName.Text &
> ";password="
> & Password.Text & ";database=" & Database.Text & ";server=" & Server.Text)
> cn.Open()
> cmdSelect.Connection = cn
> Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("Select
> * from MISRE_Threshold", cn)
> Dim dsThreshold As DataSet = New DataSet
> ' fill dataset
> da.Fill(dsThreshold, "MISRE_Threshold")
> 'Attach DataSet to DataGrid
> dgThreshold.DataSource = dsThreshold.DefaultViewManager
> Catch ex As Exception
> MessageBox.Show("Error: Could not establish database
> connection")
> End Try
>
> Private Sub btnSave_Click(ByVal sender....
> SqlDataAdapter1.Update(DataSet11)
> EndSub|||They are configured, that's why i'm stumped!
Its the update one i'm interested in as follows:
UPDATE MISRE_Threshold
SET ThresholdType = @.ThresholdType, Threshold = @.Threshold,
Threshold_Flag = @.Threshold_Flag, Actual = @.Actual, Fail = @.Fail,
Category = @.Category, ID = @.ID
WHERE (ThresholdType = @.Original_ThresholdType) AND (Actual =
@.Original_Actual) AND (Category = @.Original_Category OR
@.Original_Category IS NULL AND Category IS NULL) AND
(Fail = @.Original_Fail) AND (ID = @.Original_ID OR
@.Original_ID IS NULL AND ID IS NULL) AND (Threshold =
@.Original_Threshold OR
@.Original_Threshold IS NULL AND Threshold IS NULL) AND
(Threshold_Flag = @.Original_Threshold_Flag OR
@.Original_Threshold_Flag IS NULL AND Threshold_Flag IS
NULL);
SELECT ThresholdType, Threshold,
Threshold_Flag, Actual, Fail, Category, ID
FROM MISRE_Threshold
WHERE (ThresholdType = @.ThresholdType)|||> They are configured, that's why i'm stumped!
The original code you posted instantiates and uses a new untyped dataset:
Dim dsThreshold As DataSet = New DataSet
However, your update routine uses the DataAdapter and DataSet generated by
the windows form designer:
SqlDataAdapter1.Update(DataSet11)
DataSet11 is never filled in the code snippets you posted so it will always
be empty. I believe your intention is to fill DataSet11 in the load
routine:
SqlDataAdapter1.Fill(DataSet11)
Hope this helps.
Dan Guzman
SQL Server MVP
"marcmc" <marcmc@.discussions.microsoft.com> wrote in message
news:E94A87F0-9D2B-4DB1-85E3-5AE7635656DA@.microsoft.com...
> They are configured, that's why i'm stumped!
> Its the update one i'm interested in as follows:
>
> UPDATE MISRE_Threshold
> SET ThresholdType = @.ThresholdType, Threshold = @.Threshold,
> Threshold_Flag = @.Threshold_Flag, Actual = @.Actual, Fail = @.Fail,
> Category = @.Category, ID = @.ID
> WHERE (ThresholdType = @.Original_ThresholdType) AND (Actual =
> @.Original_Actual) AND (Category = @.Original_Category OR
> @.Original_Category IS NULL AND Category IS NULL) AND
> (Fail = @.Original_Fail) AND (ID = @.Original_ID OR
> @.Original_ID IS NULL AND ID IS NULL) AND (Threshold =
> @.Original_Threshold OR
> @.Original_Threshold IS NULL AND Threshold IS NULL)
> AND
> (Threshold_Flag = @.Original_Threshold_Flag OR
> @.Original_Threshold_Flag IS NULL AND Threshold_Flag
> IS
> NULL);
> SELECT ThresholdType, Threshold,
> Threshold_Flag, Actual, Fail, Category, ID
> FROM MISRE_Threshold
> WHERE (ThresholdType = @.ThresholdType)

Datagrid and sql query isssue. Revenue reporting system

Hi-

I am trying to develop a page that pulls all customers from a database and display the revenue for each customer for each day I query in a months time.

I am able to pull out the revenue for one day in the month and display it in the column with the appropriate revenue next to the customer name.

My problem is two things.

1. It only displays customers that actually have revenue. So how would I get my datagrid to display all customers regardless if they have revenue in the database.

2. I need to be able to display more than 1 day in columns format. For example

Customer | Day1 | Day 2 |
----------
Acme Inc | $2200. |$1300.

Here is my sql code that pulls out the customers that have revenue and displays one day between a specific set of dates.

SQL = "SELECT pb_customers.customer_name AS 'customer', sum(pb_report_shippers.total_ext_price + pb_report_shippers.setup_cost) as 'total' FROM pb_report_shippers INNER JOIN pb_jobs ON pb_report_shippers.job_id = pb_jobs.job_id INNER JOIN pb_customers ON pb_jobs.customer_id = pb_customers.customer_id WHERE pb_report_shippers.shipper_date_time between cast('9/01/03' as datetime) and cast('9/02/03' as datetime) AND job_completed = '1' GROUP by pb_customers.customer_name"

Any help would be appreciated

ThanksTo get all customers, you'll want a left outer join for your related tables. Then try something like this


SELECT pb_customers.customer_name AS 'customer',
sum(case (when day(pb_report_shippers.shipper_date_time) = 1
then pb_report_shippers.total_ext_price + pb_report_shippers.setup_cost
else 0
end) as day1,
sum(case (when day(pb_report_shippers.shipper_date_time) = 2
then pb_report_shippers.total_ext_price + pb_report_shippers.setup_cost
else 0
end) as day2,
... and so on

FROM pb_report_shippers
Left outer JOIN pb_jobs ON pb_report_shippers.job_id = pb_jobs.job_id
left outer JOIN pb_customers ON pb_jobs.customer_id = pb_customers.customer_id WHERE pb_report_shippers.shipper_date_time between cast('9/01/03' as datetime) and cast('9/02/03' as datetime) AND job_completed = '1' GROUP by pb_customers.customer_name

HTH|||Thanks for the reply.

I am confused about this line.

sum(case (when day(pb_report_shippers.shipper_date_time) = 1

then pb_report_shippers.total_ext_price + pb_report_shippers.setup_cost

else 0

end) as day1,

What does the "1" represent. Am I supposed to put the datevalue I am looking for right there? When I do i get an error with the "when" keyword.|||The DAY() function returns the DD portion of MM/DD/YYYY. So, for 10/23/2003 it would contain 23. I don't think this is exactly what you are looking for, but the methodology should work. Instead I would use the DATEDIFF() function.


SELECT
pb_customers.customer_name AS 'customer',
SUM(
CASE
WHEN DATEDIFF(d,pb_report_shippers.shipper_date_time,CAST('9/01/03' AS datetime)) = 1
THEN pb_report_shippers.total_ext_price + pb_report_shippers.setup_cost
ELSE 0
END
) AS day1,
SUM(
CASE
WHEN DATEDIFF(d,pb_report_shippers.shipper_date_time,CAST('9/01/03' AS datetime)) = 2
THEN pb_report_shippers.total_ext_price + pb_report_shippers.setup_cost
ELSE 0
END
) AS day2,
SUM(
CASE
WHEN DATEDIFF(d,pb_report_shippers.shipper_date_time,cast('9/01/03' AS datetime)) = 3
THEN pb_report_shippers.total_ext_price + pb_report_shippers.setup_cost
ELSE 0
END
) AS day3,
... and so on
FROM
pb_report_shippers
LEFT OUTER JOIN
pb_jobs ON pb_report_shippers.job_id = pb_jobs.job_id
LEFT OUTER JOIN
pb_customers ON pb_jobs.customer_id = pb_customers.customer_id
WHERE
pb_report_shippers.shipper_date_time between cast('9/01/03' as datetime) and cast('9/02/03' as datetime) AND
job_completed = '1'
GROUP BY
pb_customers.customer_name

Terri|||thanks for the help. I am getting closer to what I need.

One thing that is still occuring however is it only displays the customers that have revenue. It wont display all customers regardless is no revenue is found in the database. Is this what the left outer join is suppoesed to handle. What does it doe exactly compated to a normal Inner join.|||The left outer join should accomplish this. experiment a bit and comment out the


LEFT OUTER JOIN

pb_customers ON pb_jobs.customer_id = pb_customers.customer_id


and any related columns of the query to see if you get the same results. This should help you track down why not all customers are showing up.|||Then I would restruture slightly. I would make the primary table you are pulling from your customers table, and I would LEFT OUTER join your shippers table. Like this (untested but hopefully it's close):

SELECT
pb_customers.customer_name AS 'customer',
SUM(
CASE
WHEN DATEDIFF(d,pb_report_shippers.shipper_date_time,CAST('9/01/03' AS datetime)) = 1
THEN pb_report_shippers.total_ext_price + pb_report_shippers.setup_cost
ELSE 0
END
) AS day1,
SUM(
CASE
WHEN DATEDIFF(d,pb_report_shippers.shipper_date_time,CAST('9/01/03' AS datetime)) = 2
THEN pb_report_shippers.total_ext_price + pb_report_shippers.setup_cost
ELSE 0
END
) AS day2,
SUM(
CASE
WHEN DATEDIFF(d,pb_report_shippers.shipper_date_time,cast('9/01/03' AS datetime)) = 3
THEN pb_report_shippers.total_ext_price + pb_report_shippers.setup_cost
ELSE 0
END
) AS day3,
... and so on
FROM
pb_customers
LEFT OUTER JOIN
pb_jobs ON pb_jobs.customer_id = pb_customers.customer_id AND pb_report_shippers.shipper_date_time BETWEEN CAST('9/01/03' as datetime) AND CAST('9/02/03' as datetime) AND
job_completed = '1'
LEFT OUTER JOIN
pb_report_shippers ON pb_report_shippers.job_id = pb_jobs.job_id
GROUP BY
pb_customers.customer_name

datagrid

hey all

i have 2 tables
1. Location (locid, name)
2. Product (pid, locid, productname, ...etc)

right now i do a select * from product where locid ='locid', and a datagrid with colums
ProductId | ProductName | AvailableIn

how do i do a select * from Location where locid ='locid' and show Location Name in the datagrid?

ProductId | ProductName | AvailableIn
123456 | testing | Somewhere (instead of the locid)

thankstry this. I haven't tested this, but should give you a good indication of what is needed...


SELECT *, L.Name AS "AvailableIn'
FROM Product P
INNER JOIN Location L
ON P.locid=L.locid
WHERE P.locid='locid'

Hope that helps!
KJ
(The INNER JOIN will list all products that have a corresponding entry on the Location table. If that column was optional, you can use a LEFT JOIN)|||It should probably be


SELECTP.*, L.Name AS 'AvailableIn'......

KJ

Sunday, February 26, 2012

Databinding in c# - Important

Hello
All the samples I found are based on datagrid for the child table.
What if I don't want the child records to be displayed in a datagrid, but in
their own data bound controls like "text box, combo & list boxes). And I
want to provide a second level of navigation buttons to traverse those child
records in the child table.
I'm sure this is possible, but I can't seem to find any sample on it.
Please let me know if you can throw any light on it.
Thank You
You can use the BindingContext and the BindingManagerBase classes to
accomplish this... using the Control.DataBindings.Add( , , )
I don't have any sample off of the top of my head but if you put in
BindingContext and BindingManagerBase in google, you'll find some
W.G. Ryan, MVP
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Hemang Shah" <hemang@.hemang.net> wrote in message
news:ToidnScZwb7iqGjcRVn-ow@.rogers.com...
> Hello
> All the samples I found are based on datagrid for the child table.
> What if I don't want the child records to be displayed in a datagrid, but
in
> their own data bound controls like "text box, combo & list boxes). And I
> want to provide a second level of navigation buttons to traverse those
child
> records in the child table.
> I'm sure this is possible, but I can't seem to find any sample on it.
> Please let me know if you can throw any light on it.
> Thank You
>
>
|||Hemang,
It's the same as if you were binding to the grid. When you add the
binding for the control to the child table, you set the data source to the
relation, not to the child table itself.
Hope this helps.
- Nicholas Paldino [.NET/C# MVP]
- mvp@.spam.guard.caspershouse.com
"Hemang Shah" <hemang@.hemang.net> wrote in message
news:ToidnScZwb7iqGjcRVn-ow@.rogers.com...
> Hello
> All the samples I found are based on datagrid for the child table.
> What if I don't want the child records to be displayed in a datagrid, but
> in
> their own data bound controls like "text box, combo & list boxes). And I
> want to provide a second level of navigation buttons to traverse those
> child
> records in the child table.
> I'm sure this is possible, but I can't seem to find any sample on it.
> Please let me know if you can throw any light on it.
> Thank You
>
>